jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1057943?usp=email )
Change subject: automatically upgrade python syntax ......................................................................
automatically upgrade python syntax
Change-Id: Ic6c895a96b112d575ca711dee6c4a17f9c72f29d --- M pywikibot/backports.py M pywikibot/page/_wikibase.py M pywikibot/tools/_deprecate.py M scripts/checkimages.py M scripts/misspelling.py M scripts/redirect.py M scripts/solve_disambiguation.py 7 files changed, 19 insertions(+), 20 deletions(-)
Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/backports.py b/pywikibot/backports.py index 76f8162..901f315 100644 --- a/pywikibot/backports.py +++ b/pywikibot/backports.py @@ -134,14 +134,14 @@ next(b, None) return zip(a, b) else: - from types import NoneType from itertools import pairwise # type: ignore[no-redef] + from types import NoneType
# gh-98363 if PYTHON_VERSION < (3, 13) or SPHINX_RUNNING: def batched(iterable, n: int, *, - strict: bool = False) -> Generator[tuple, None, None]: + strict: bool = False) -> Generator[tuple]: """Batch data from the *iterable* into tuples of length *n*.
.. note:: The last batch may be shorter than *n* if *strict* is diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py index 5b34dd7..b3458f6 100644 --- a/pywikibot/page/_wikibase.py +++ b/pywikibot/page/_wikibase.py @@ -1307,7 +1307,7 @@ @deprecated_args(botflag='bot') # since 9.3.0 def set_redirect_target( self, - target_page: 'ItemPage' | str, + target_page: ItemPage | str, create: bool = False, force: bool = False, keep_section: bool = False, diff --git a/pywikibot/tools/_deprecate.py b/pywikibot/tools/_deprecate.py index 2ee8f8d..c87a964 100644 --- a/pywikibot/tools/_deprecate.py +++ b/pywikibot/tools/_deprecate.py @@ -494,7 +494,7 @@ replace_args = list(zip(arg_keys[positionals:], args[positionals:])) pos_args = "', '".join(name for name, arg in replace_args) - keyw_args = ', '.join('{}={!r}'.format(name, arg) + keyw_args = ', '.join(f'{name}={arg!r}' for name, arg in replace_args) issue_deprecation_warning( f"Passing '{pos_args}' as positional " diff --git a/scripts/checkimages.py b/scripts/checkimages.py index e06725f..0b24bf5 100755 --- a/scripts/checkimages.py +++ b/scripts/checkimages.py @@ -739,8 +739,11 @@ except NotEmailableError: pywikibot.info('User is not mailable, aborted')
- def regex_generator(self, regexp, textrun) -> Generator[pywikibot.FilePage, - None, None]: + def regex_generator( + self, + regexp, + textrun, + ) -> Generator[pywikibot.FilePage]: """Find page to yield using regex to parse text.""" regex = re.compile(fr'{regexp}', re.DOTALL) results = regex.findall(textrun) @@ -1312,8 +1315,7 @@ return False
@staticmethod - def wait(generator, wait_time) -> Generator[pywikibot.FilePage, None, - None]: + def wait(generator, wait_time) -> Generator[pywikibot.FilePage]: """ Skip the images uploaded before x seconds.
diff --git a/scripts/misspelling.py b/scripts/misspelling.py index acaf624..46830c8 100755 --- a/scripts/misspelling.py +++ b/scripts/misspelling.py @@ -58,7 +58,7 @@ update_options = {'start': None}
@property - def generator(self) -> Generator[pywikibot.Page, None, None]: + def generator(self) -> Generator[pywikibot.Page]: """Generator to retrieve misspelling pages or misspelling redirects.""" templates = self.misspelling_templates.get(self.site.sitename) categories = [cat for cat in (self.site.page_from_repository(item) diff --git a/scripts/redirect.py b/scripts/redirect.py index faeca78..1e0cb11 100755 --- a/scripts/redirect.py +++ b/scripts/redirect.py @@ -199,8 +199,7 @@ space_to_underscore(target_link)) return redict, pageTitles
- def get_redirect_pages_via_api(self) -> Generator[pywikibot.Page, None, - None]: + def get_redirect_pages_via_api(self) -> Generator[pywikibot.Page]: """Yield Pages that are redirects.""" for ns in self.opt.namespaces: gen = self.site.allpages(start=self.opt.start, @@ -215,8 +214,7 @@ return yield p
- def _next_redirect_group(self) -> Generator[list[pywikibot.Page], None, - None]: + def _next_redirect_group(self) -> Generator[list[pywikibot.Page]]: """Generator that yields batches of redirects as a list.""" chunk = [] for page in self.get_redirect_pages_via_api(): @@ -231,7 +229,7 @@ def get_redirects_via_api( self, maxlen: int = 8 - ) -> Generator[tuple[str, int | None, str, str | None], None, None]: + ) -> Generator[tuple[str, int | None, str, str | None]]: r""" Return a generator that yields tuples of data about redirect Pages.
@@ -295,7 +293,7 @@ yield redirect, result, target, final
def retrieve_broken_redirects(self) -> Generator[ - str | pywikibot.Page, None, None]: + str | pywikibot.Page]: """Retrieve broken redirects.""" if self.opt.fullscan: count = 0 @@ -319,7 +317,7 @@ yield from self.site.preloadpages(self.site.broken_redirects())
def retrieve_double_redirects(self) -> Generator[ - str | pywikibot.Page, None, None]: + str | pywikibot.Page]: """Retrieve double redirects.""" if self.opt.moves: yield from self.get_moved_pages_redirects() @@ -344,8 +342,7 @@ pywikibot.info('Retrieving double redirect special page...') yield from self.site.preloadpages(self.site.double_redirects())
- def get_moved_pages_redirects(self) -> Generator[pywikibot.Page, None, - None]: + def get_moved_pages_redirects(self) -> Generator[pywikibot.Page]: """Generate redirects to recently-moved pages.""" # this will run forever, until user interrupts it if self.opt.offset <= 0: diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index f9ba4de..2f309d8 100755 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -413,7 +413,7 @@ self.minimum = minimum self.main_only = main_only
- def __iter__(self) -> Generator[pywikibot.Page, None, None]: + def __iter__(self) -> Generator[pywikibot.Page]: """Yield pages.""" # TODO: start yielding before all referring pages have been found refs = list(self.page.getReferences(with_template_inclusion=False, @@ -680,7 +680,7 @@ (?P<linktrail>{linktrail})""", flags=re.X)
@staticmethod - def firstlinks(page) -> Generator[str, None, None]: + def firstlinks(page) -> Generator[str]: """Return a list of first links of every line beginning with `*`.
When a disambpage is full of unnecessary links, this may be useful
pywikibot-commits@lists.wikimedia.org