jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/704872 )
Change subject: [IMPR] backports.py type hints ......................................................................
[IMPR] backports.py type hints
Tiny module so this is a tiny adjustment. This includes some trivial cleanup that doesn't seem worth a separate review.
* Returning "string[:]" is identical to just the string. * Use Sphinx's versionadded role.
Bug: T286403 Change-Id: I457881dea06b17274e2ec5b77afbb1a5cc67b1f9 --- M pywikibot/backports.py 1 file changed, 9 insertions(+), 7 deletions(-)
Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/backports.py b/pywikibot/backports.py index 85bf4a2..5bab31d 100644 --- a/pywikibot/backports.py +++ b/pywikibot/backports.py @@ -4,6 +4,8 @@ # # Distributed under the terms of the MIT license. # +from typing import Any + from pywikibot.tools import PYTHON_VERSION
@@ -22,13 +24,13 @@
"""Dummy context manager for Python 3.5/3.6 that does nothing."""
- def __init__(self, result=None): # noqa: D107 + def __init__(self, result: Any = None) -> None: # noqa: D107 self.result = result
- def __enter__(self): + def __enter__(self) -> Any: return self.result
- def __exit__(self, *args): + def __exit__(self, *args) -> None: pass else: from contextlib import nullcontext @@ -77,17 +79,17 @@ def removeprefix(string: str, prefix: str) -> str: """Remove prefix from a string or return a copy otherwise.
- *New in version 5.4.* + .. versionadded:: 5.4 """ if string.startswith(prefix): return string[len(prefix):] - return string[:] + return string
def removesuffix(string: str, suffix: str) -> str: """Remove prefix from a string or return a copy otherwise.
- *New in version 5.4.* + .. versionadded:: 5.4 """ if string.endswith(suffix): return string[:-len(suffix)] - return string[:] + return string
pywikibot-commits@lists.wikimedia.org