jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/986636 )

Change subject: update typing syntax for 3.7
......................................................................

update typing syntax for 3.7

Follow-Up: I8864b90799373b442a3147b823cc5dd10eedf3a0

Change-Id: I60ba68d08f6170cace0ffc1ff685c3783ecbe57d
---
M pwb.py
M ROADMAP.rst
M docs/conf.py
M pywikibot/pagegenerators/_filters.py
M pywikibot/pagegenerators/_generators.py
M tests/tools_chars_tests.py
M pywikibot/family.py
M pywikibot/scripts/i18n/__init__.py
M setup.py
M pywikibot/page/_basepage.py
M pywikibot/page/_wikibase.py
M tests/tools_tests.py
M tests/tests_tests.py
M pywikibot/i18n.py
M pywikibot/page/_links.py
M pywikibot/userinterfaces/__init__.py
M pywikibot/fixes.py
M pywikibot/config.py
M pywikibot/bot.py
M tests/pwb/__init__.py
M pywikibot/page/_collections.py
M pywikibot/textlib.py
M pywikibot/__init__.py
M pywikibot/site/__init__.py
M tests/i18n/__init__.py
M pywikibot/plural.py
M pywikibot/pagegenerators/__init__.py
M pywikibot/pagegenerators/_factory.py
M pywikibot/xmlreader.py
M pywikibot/backports.py
M scripts/userscripts/__init__.py
M pywikibot/date.py
M pywikibot/site/_apisite.py
M pywikibot/_wbtypes.py
M tests/diff_tests.py
M scripts/__init__.py
M tests/pagegenerators_tests.py
M tox.ini
M pywikibot/proofreadpage.py
39 files changed, 145 insertions(+), 147 deletions(-)

Approvals:
  JJMC89: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/ROADMAP.rst b/ROADMAP.rst
index 5026fdf..22f6916 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -4,7 +4,7 @@
 Improvements
 ^^^^^^^^^^^^

-* Add 
:meth:`site.APISite.ratelimit()<pywikibot.site._apisite.APISite.ratelimit>` 
method
+* Add 
:meth:`site.APISite.ratelimit()<pywikibot.site._apisite.APISite.ratelimit>` 
method
   and :class:`tools.collections.RateLimit` NamedTuple (:phab:`T304808`)
 * L10N Updates
 * Add :class:`pagegenerators.PagePilePageGenerator` (:phab:`T353086`)
diff --git a/docs/conf.py b/docs/conf.py
index 029daec..5ca8569 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -15,6 +15,7 @@
 #
 # All configuration values have a default; values that are commented out
 # serve to show the default.
+from __future__ import annotations

 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
diff --git a/pwb.py b/pwb.py
index e62c0b8..809af16 100755
--- a/pwb.py
+++ b/pwb.py
@@ -11,6 +11,7 @@
 import runpy
 import sys

+
 VERSIONS_REQUIRED_MESSAGE = """
 Pywikibot is not available on:
 {version}
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 93778ab..22002d8 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -40,11 +40,7 @@
     WbTime,
     WbUnknown,
 )
-from pywikibot.backports import (
-    Callable,
-    cache,
-    removesuffix,
-)
+from pywikibot.backports import Callable, cache, removesuffix
 from pywikibot.bot import (
     Bot,
     CurrentPageBot,
diff --git a/pywikibot/_wbtypes.py b/pywikibot/_wbtypes.py
index e260de8..8a9f410 100644
--- a/pywikibot/_wbtypes.py
+++ b/pywikibot/_wbtypes.py
@@ -12,7 +12,7 @@
 import math
 import re
 from decimal import Decimal
-from typing import TYPE_CHECKING, Any, Union
+from typing import TYPE_CHECKING, Any

 import pywikibot
 from pywikibot import exceptions
@@ -24,8 +24,9 @@
 if TYPE_CHECKING:
     from pywikibot.site import APISite, BaseSite, DataSite

-ItemPageStrNoneType = Union[str, 'pywikibot.ItemPage', None]
-ToDecimalType = Union[int, float, str, 'Decimal', None]
+    ItemPageStrNoneType = str | pywikibot.ItemPage | None
+    ToDecimalType = int | float | str | Decimal | None
+

 __all__ = (
     'Coordinate',
diff --git a/pywikibot/backports.py b/pywikibot/backports.py
index 04a334e..61822ae 100644
--- a/pywikibot/backports.py
+++ b/pywikibot/backports.py
@@ -47,18 +47,13 @@
         Container,
         Counter,
         Dict,
-        FrozenSet,
         Generator,
         Iterable,
         Iterator,
-        List,
         Mapping,
         Match,
         Pattern,
         Sequence,
-        Set,
-        Tuple,
-        Type,
     )
 else:
     from collections import Counter
@@ -72,11 +67,6 @@
     )
     from re import Match, Pattern
     Dict = dict  # type: ignore[misc]
-    FrozenSet = frozenset  # type: ignore[misc]
-    List = list  # type: ignore[misc]
-    Set = set  # type: ignore[misc]
-    Tuple = tuple  # type: ignore[assignment]
-    Type = type


 if PYTHON_VERSION < (3, 9, 2):
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index d1827d4..59882ea 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -108,19 +108,12 @@
 from importlib import import_module
 from pathlib import Path
 from textwrap import fill
-from typing import TYPE_CHECKING, Any, Optional, Union
+from typing import TYPE_CHECKING, Any
 from warnings import warn

 import pywikibot
 from pywikibot import config, daemonize, i18n, version
-from pywikibot.backports import (
-    Callable,
-    Dict,
-    Iterable,
-    Mapping,
-    Sequence,
-    Tuple,
-)
+from pywikibot.backports import Callable, Dict, Iterable, Mapping, Sequence
 from pywikibot.bot_choice import (
     AlwaysChoice,
     Choice,
@@ -182,8 +175,7 @@
     from pywikibot.page import Link, Page
     from pywikibot.site import BaseSite

-
-AnswerType = Union[Iterable[Union[Tuple[str, str], Option]], Option]
+    AnswerType = Iterable[tuple[str, str] | Option] | Option

 _GLOBAL_HELP = """
 GLOBAL OPTIONS
@@ -701,14 +693,13 @@
         self._default = default
         self._quit = automatic_quit

-        current_match_type = Optional[tuple[  # skipcq: PYL-W0612
+        self._current_match: tuple[
             Link | Page,
             str,
             Mapping[str, str],
             tuple[int, int]
-        ]]
+        ] | None = None

-        self._current_match: current_match_type = None
         self.context = 30
         self.context_delta = 0
         self.allow_skip_link = True
diff --git a/pywikibot/config.py b/pywikibot/config.py
index a64f21c..c6e170a 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -52,14 +52,13 @@
 from os import environ, getenv
 from pathlib import Path
 from textwrap import fill
-from typing import TypeVar
+from typing import TYPE_CHECKING, TypeVar
 from warnings import warn
 from zipfile import ZipFile, is_zipfile

 from pywikibot.__metadata__ import __version__ as pwb_version
 from pywikibot.backports import (
     DefaultDict,
-    Dict,
     Mapping,
     removeprefix,
     removesuffix,
@@ -67,7 +66,9 @@
 from pywikibot.logging import error, info, warning


-_DabComDict = DefaultDict[str, Dict[str, str]]
+if TYPE_CHECKING:
+    _DabComDict = DefaultDict[str, dict[str, str]]
+
 _ValueType = TypeVar('_ValueType')


diff --git a/pywikibot/date.py b/pywikibot/date.py
index 74cf19b..d79aa47 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -13,24 +13,34 @@
 from contextlib import suppress
 from functools import singledispatch
 from string import digits as _decimalDigits  # noqa: N812
-from typing import Union
+from typing import TYPE_CHECKING

 from pywikibot import Site
 from pywikibot.backports import (
     Any,
     Callable,
     Iterator,
-    List,
     Mapping,
     Pattern,
     Sequence,
-    Tuple,
 )
 from pywikibot.site import BaseSite
 from pywikibot.textlib import NON_LATIN_DIGITS
 from pywikibot.tools import first_lower, first_upper


+if TYPE_CHECKING:
+    tuplst_type = list[tuple[Callable[[int | str], Any],
+                             Callable[[int | str], bool]]]
+    encf_type = Callable[[int], int | Sequence[int]]
+    decf_type = Callable[[Sequence[int]], int]
+    # decoders are three value tuples, with an optional fourth to represent a
+    # required number of digits
+    decoder_type = (
+        tuple[str, Callable[[int], str], Callable[[str], int]]
+        | tuple[str, Callable[[int], str], Callable[[str], int], int]
+    )
+
 #
 # Different collections of well known formats
 #
@@ -55,18 +65,6 @@
 yearFormats = ['YearAD', 'YearBC']
 millFormats = ['MillenniumAD', 'MillenniumBC']
 snglValsFormats = ['CurrEvents']
-tuplst_type = List[Tuple[Callable[[Union[int, str]], Any],
-                         Callable[[Union[int, str]], bool]]]
-encf_type = Callable[[int], Union[int, Sequence[int]]]
-decf_type = Callable[[Sequence[int]], int]
-
-# decoders are three value tuples, with an optional fourth to represent a
-# required number of digits
-
-decoder_type = Union[
-    Tuple[str, Callable[[int], str], Callable[[str], int]],
-    Tuple[str, Callable[[int], str], Callable[[str], int], int]
-]


 @singledispatch
@@ -571,8 +569,7 @@
         'zh': lambda v: slh(v, makeMonthList('%d月')),
     }

-    def __getitem__(self, lang: str
-                    ) -> Callable[[int], str]:
+    def __getitem__(self, lang: str) -> Callable[[int], str]:
         if lang not in self.months:
             site = Site()
             # may_long differs
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 0d66239..fa48156 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -18,24 +18,19 @@
 from itertools import chain
 from os.path import basename, dirname, splitext
 from textwrap import fill
+from typing import TYPE_CHECKING

 import pywikibot
 from pywikibot import config
-from pywikibot.backports import (
-    DefaultDict,
-    Dict,
-    List,
-    Mapping,
-    Sequence,
-    removesuffix,
-)
+from pywikibot.backports import DefaultDict, Mapping, Sequence, removesuffix
 from pywikibot.exceptions import FamilyMaintenanceWarning, UnknownFamilyError
 from pywikibot.tools import classproperty, deprecated, remove_last_args


 logger = logging.getLogger('pywiki.wiki.family')

-CrossnamespaceType = DefaultDict[str, Dict[str, List[int]]]
+if TYPE_CHECKING:
+    CrossnamespaceType = DefaultDict[str, dict[str, list[int]]]

 # Legal characters for Family.name and Family.langs keys
 NAME_CHARACTERS = string.ascii_letters + string.digits
diff --git a/pywikibot/fixes.py b/pywikibot/fixes.py
index 259cb96..db65059 100644
--- a/pywikibot/fixes.py
+++ b/pywikibot/fixes.py
@@ -4,6 +4,8 @@
 #
 # Distributed under the terms of the MIT license.
 #
+from __future__ import annotations
+
 import os.path

 from pywikibot import config
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 0d9fa27..675c87b 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -29,7 +29,6 @@
 from contextlib import suppress
 from pathlib import Path
 from textwrap import fill
-from typing import Union

 import pywikibot
 from pywikibot import __url__, config
@@ -46,8 +45,6 @@
 from pywikibot.plural import plural_rule


-STR_OR_SITE_TYPE = Union[str, 'pywikibot.site.BaseSite']
-
 PLURAL_PATTERN = r'{{PLURAL:(?:%\()?([^\)]*?)(?:\)d)?\|(.*?)}}'

 # Package name for the translation messages. The messages data must loaded
@@ -558,7 +555,7 @@
 DEFAULT_FALLBACK = ('_default', )


-def translate(code: STR_OR_SITE_TYPE,
+def translate(code: str | pywikibot.site.BaseSite,
               xdict: str | Mapping[str, str],
               parameters: Mapping[str, int] | None = None,
               fallback: bool | Iterable[str] = False) -> str | None:
@@ -654,7 +651,10 @@
     return trans


-def get_bot_prefix(source: STR_OR_SITE_TYPE, use_prefix: bool) -> str:
+def get_bot_prefix(
+    source: str | pywikibot.site.BaseSite,
+    use_prefix: bool
+) -> str:
     """Get the bot prefix string like 'Bot: ' including space delimiter.

     .. note: If *source* is a str and ``config.bot_prefix`` is set to
@@ -690,7 +690,7 @@


 def twtranslate(
-    source: STR_OR_SITE_TYPE,
+    source: str | pywikibot.site.BaseSite,
     twtitle: str,
     parameters: Sequence[str] | Mapping[str, int] | None = None,
     *,
@@ -822,7 +822,7 @@
     return prefix + trans


-def twhas_key(source: STR_OR_SITE_TYPE, twtitle: str) -> bool:
+def twhas_key(source: str | pywikibot.site.BaseSite, twtitle: str) -> bool:
     """
     Check if a message has a translation in the specified language code.

diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index 9ff008c..f38eece 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -17,12 +17,7 @@

 import pywikibot
 from pywikibot import Timestamp, config, date, i18n, textlib, tools
-from pywikibot.backports import (
-    Generator,
-    Iterable,
-    Iterator,
-    List,
-)
+from pywikibot.backports import Generator, Iterable, Iterator
 from pywikibot.cosmetic_changes import CANCEL, CosmeticChangesToolkit
 from pywikibot.exceptions import (
     Error,
@@ -1947,7 +1942,7 @@
         timestamp,
         content: bool = False,
         **kwargs
-    ) -> List:
+    ) -> list:
         """
         Return a particular deleted revision by timestamp.

diff --git a/pywikibot/page/_collections.py b/pywikibot/page/_collections.py
index 9a96f35..8f4ac1a 100644
--- a/pywikibot/page/_collections.py
+++ b/pywikibot/page/_collections.py
@@ -8,6 +8,7 @@

 from collections import defaultdict
 from collections.abc import MutableMapping, MutableSequence
+from typing import Any

 import pywikibot
 from pywikibot.site import BaseSite
@@ -374,7 +375,11 @@
         self._data[key] = val
         return val

-    def __setitem__(self, key, val) -> None:
+    def __setitem__(
+        self,
+        key: str | pywikibot.site.APISite,
+        val: str | dict[str, Any] | pywikibot.page.SiteLink,
+    ) -> None:
         """
         Set the SiteLink for a given key.

@@ -383,10 +388,8 @@
         __getitem__ method.

         :param key: site key as Site instance or db key
-        :type key: pywikibot.Site or str
         :param val: page name as a string or JSON containing SiteLink
             data or a SiteLink object
-        :type val: Union[str, dict, SiteLink]
         """
         key = self.getdbName(key)
         if isinstance(val, pywikibot.page.SiteLink):
diff --git a/pywikibot/page/_links.py b/pywikibot/page/_links.py
index d043a8f..a9a8601 100644
--- a/pywikibot/page/_links.py
+++ b/pywikibot/page/_links.py
@@ -15,6 +15,7 @@
 import re
 import unicodedata
 from html.entities import name2codepoint
+from typing import Any

 import pywikibot
 from pywikibot import textlib
@@ -734,15 +735,17 @@
         return list(self._badges)

     @classmethod
-    def fromJSON(cls, data: dict, site=None):  # noqa: N802
+    def fromJSON(  # noqa: N802
+        cls,
+        data: dict[str, Any],
+        site: pywikibot.site.DataSite | None = None,
+    ) -> SiteLink:
         """
         Create a SiteLink object from JSON returned in the API call.

         :param data: JSON containing SiteLink data
         :param site: The Wikibase site
         :type site: pywikibot.site.DataSite
-
-        :rtype: pywikibot.page.SiteLink
         """
         sl = cls(data['title'], data['site'])
         repo = site or sl.site.data_repository()
@@ -750,7 +753,7 @@
             sl._badges.add(pywikibot.ItemPage(repo, badge))
         return sl

-    def toJSON(self) -> dict:  # noqa: N802
+    def toJSON(self) -> dict[str, str | list[str]]:  # noqa: N802
         """
         Convert the SiteLink to a JSON object for the Wikibase API.

diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 7711a9d..34607ce 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -20,10 +20,9 @@
 from collections import OrderedDict, defaultdict
 from contextlib import suppress
 from itertools import chain
-from typing import Any, Union
+from typing import TYPE_CHECKING, Any

 import pywikibot
-from pywikibot.backports import Dict, List
 from pywikibot.exceptions import (
     APIError,
     EntityTypeUnknownError,
@@ -65,13 +64,16 @@
     'WikibasePage',
 )

-
-LANGUAGE_IDENTIFIER = Union[str, pywikibot.APISite]
-ALIASES_TYPE = Dict[LANGUAGE_IDENTIFIER, List[str]]
-LANGUAGE_TYPE = Dict[LANGUAGE_IDENTIFIER, str]
-SITELINK_TYPE = Union['pywikibot.page.BasePage', 'pywikibot.page.BaseLink',
-                      Dict[str, str]]
-ENTITY_DATA_TYPE = Dict[str, Union[LANGUAGE_TYPE, ALIASES_TYPE, SITELINK_TYPE]]
+if TYPE_CHECKING:
+    LANGUAGE_IDENTIFIER = str | pywikibot.APISite
+    ALIASES_TYPE = dict[LANGUAGE_IDENTIFIER, list[str]]
+    LANGUAGE_TYPE = dict[LANGUAGE_IDENTIFIER, str]
+    SITELINK_TYPE = (
+        pywikibot.page.BasePage
+        | pywikibot.page.BaseLink
+        | dict[str, str]
+    )
+    ENTITY_DATA_TYPE = dict[str, LANGUAGE_TYPE | ALIASES_TYPE | SITELINK_TYPE]


 class WikibaseEntity:
diff --git a/pywikibot/pagegenerators/__init__.py 
b/pywikibot/pagegenerators/__init__.py
index 35f2b87..eca2326 100644
--- a/pywikibot/pagegenerators/__init__.py
+++ b/pywikibot/pagegenerators/__init__.py
@@ -19,10 +19,10 @@
 #
 from __future__ import annotations

-from typing import Any
+from typing import TYPE_CHECKING, Any

 import pywikibot
-from pywikibot.backports import Callable, Dict, Iterable, Iterator, List
+from pywikibot.backports import Callable, Iterable, Iterator
 from pywikibot.pagegenerators._factory import GeneratorFactory
 from pywikibot.pagegenerators._filters import (
     CategoryFilterPageGenerator,
@@ -58,9 +58,9 @@
     MySQLPageGenerator,
     NewimagesPageGenerator,
     NewpagesPageGenerator,
+    PagePilePageGenerator,
     PagesFromPageidGenerator,
     PagesFromTitlesGenerator,
-    PagePilePageGenerator,
     PetScanPageGenerator,
     PrefixingPageGenerator,
     RandomPageGenerator,
@@ -529,7 +529,9 @@

 docuReplacements = {'&params;': parameterHelp}  # noqa: N816

-PRELOAD_SITE_TYPE = Dict[pywikibot.site.BaseSite, List[pywikibot.page.Page]]
+if TYPE_CHECKING:
+    PRELOAD_SITE_TYPE = dict[pywikibot.site.BaseSite,
+                             list[pywikibot.page.Page]]

 # if a bot uses GeneratorFactory, the module should include the line
 #   docuReplacements = {'&params;': pywikibot.pagegenerators.parameterHelp}
diff --git a/pywikibot/pagegenerators/_factory.py 
b/pywikibot/pagegenerators/_factory.py
index 79fec88..80c8081 100644
--- a/pywikibot/pagegenerators/_factory.py
+++ b/pywikibot/pagegenerators/_factory.py
@@ -12,18 +12,15 @@
 from datetime import timedelta
 from functools import partial
 from itertools import zip_longest
-from typing import TYPE_CHECKING, Any, Optional, Union
+from typing import TYPE_CHECKING, Any

 import pywikibot
 from pywikibot import i18n
 from pywikibot.backports import (
     Callable,
-    Dict,
     Iterable,
     Iterator,
-    List,
     Sequence,
-    Tuple,
     removeprefix,
 )
 from pywikibot.bot import ShowingListOption
@@ -69,10 +66,9 @@
 if TYPE_CHECKING:
     from pywikibot.site import BaseSite, Namespace

-
-HANDLER_RETURN_TYPE = Union[None, bool, Iterable['pywikibot.page.BasePage']]
-GEN_FACTORY_CLAIM_TYPE = List[Tuple[str, str, Dict[str, str], bool]]
-OPT_GENERATOR_TYPE = Optional[Iterable['pywikibot.page.Page']]
+    HANDLER_RETURN_TYPE = bool, Iterable[pywikibot.page.BasePage] | None
+    GEN_FACTORY_CLAIM_TYPE = list[tuple[str, str, dict[str, str], bool]]
+    OPT_GENERATOR_TYPE = Iterable[pywikibot.page.Page] | None


 # This is the function that will be used to de-duplicate page iterators.
diff --git a/pywikibot/pagegenerators/_filters.py 
b/pywikibot/pagegenerators/_filters.py
index 500bc12..f85496d 100644
--- a/pywikibot/pagegenerators/_filters.py
+++ b/pywikibot/pagegenerators/_filters.py
@@ -9,18 +9,11 @@
 import datetime
 import re
 from functools import partial
-from typing import TYPE_CHECKING, NamedTuple, Union
+from typing import TYPE_CHECKING, NamedTuple

 import pywikibot
 from pywikibot import config
-from pywikibot.backports import (
-    Dict,
-    Iterable,
-    Iterator,
-    List,
-    Pattern,
-    Sequence,
-)
+from pywikibot.backports import Iterable, Iterator, Pattern, Sequence
 from pywikibot.exceptions import NoPageError
 from pywikibot.proofreadpage import ProofreadPage
 from pywikibot.tools.itertools import filter_unique
@@ -29,10 +22,14 @@
 if TYPE_CHECKING:
     from pywikibot.site import BaseSite, Namespace

-
-PRELOAD_SITE_TYPE = Dict[pywikibot.site.BaseSite, List[pywikibot.page.Page]]
-PATTERN_STR_OR_SEQ_TYPE = Union[str, Pattern[str],
-                                Sequence[str], Sequence[Pattern[str]]]
+    PRELOAD_SITE_TYPE = dict[pywikibot.site.BaseSite,
+                             list[pywikibot.page.Page]]
+    PATTERN_STR_OR_SEQ_TYPE = (
+        str
+        | Pattern[str]
+        | Sequence[str]
+        | Sequence[Pattern[str]]
+    )


 # This is the function that will be used to de-duplicate page iterators.
diff --git a/pywikibot/pagegenerators/_generators.py 
b/pywikibot/pagegenerators/_generators.py
index 296640b..80cc3ee 100644
--- a/pywikibot/pagegenerators/_generators.py
+++ b/pywikibot/pagegenerators/_generators.py
@@ -1281,7 +1281,7 @@
         yield from raw_pages

     @property
-    def generator(self) -> Iterator['pywikibot.page.Page']:
+    def generator(self) -> Iterator[pywikibot.page.Page]:
         """Yield results from :meth:`query`."""
         for raw_page in self.query():
             page = pywikibot.Page(self.site, raw_page)
diff --git a/pywikibot/plural.py b/pywikibot/plural.py
index f5dd442..df526d5 100644
--- a/pywikibot/plural.py
+++ b/pywikibot/plural.py
@@ -6,10 +6,11 @@
 #
 from __future__ import annotations

-from typing import Dict, Callable, Union
+from typing import TYPE_CHECKING, Callable


-PluralRule = Dict[str, Union[int, Callable[[int], Union[bool, int]]]]
+if TYPE_CHECKING:
+    PluralRule = dict[str, int | Callable[[int], bool | int]]

 plural_rules: dict[str, PluralRule] = {
     '_default': {'nplurals': 2, 'plural': lambda n: (n != 1)},
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py
index 050c6e9..7e7c24e 100644
--- a/pywikibot/proofreadpage.py
+++ b/pywikibot/proofreadpage.py
@@ -42,12 +42,7 @@

 import pywikibot
 from pywikibot import textlib
-from pywikibot.backports import (
-    Callable,
-    Iterable,
-    Sequence,
-    pairwise,
-)
+from pywikibot.backports import Callable, Iterable, Sequence, pairwise
 from pywikibot.comms import http
 from pywikibot.data.api import ListGenerator, Request
 from pywikibot.exceptions import Error, InvalidTitleError, OtherPageSaveError
diff --git a/pywikibot/scripts/i18n/__init__.py 
b/pywikibot/scripts/i18n/__init__.py
index 8bd476e..4b4df0e 100644
--- a/pywikibot/scripts/i18n/__init__.py
+++ b/pywikibot/scripts/i18n/__init__.py
@@ -3,6 +3,9 @@
 This file exists to help pkgutil find the i18n data. There is no actual
 python code in this package.
 """
+from __future__ import annotations
+
+
 #
 # (C) Pywikibot team, 2011-2022
 #
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 8a7c5d4..6824eb1 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -6,8 +6,9 @@
 #
 from __future__ import annotations

+
 # to prevent ImportError exception due to circular imports
-from pywikibot.site._namespace import Namespace, NamespacesDict
+from pywikibot.site._namespace import Namespace, NamespacesDict  # isort: split

 from pywikibot.site._apisite import APISite
 from pywikibot.site._basesite import BaseSite
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 380811b..9aa95d4 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -13,7 +13,7 @@
 from collections import OrderedDict, defaultdict
 from contextlib import suppress
 from textwrap import fill
-from typing import TYPE_CHECKING, Any, NamedTuple, TypeVar, Union
+from typing import TYPE_CHECKING, Any, NamedTuple, TypeVar

 import pywikibot
 from pywikibot import login
@@ -84,14 +84,14 @@
 if TYPE_CHECKING:
     from pywikibot.page import BasePage

+    _CompType = int | str | pywikibot.page.Page | pywikibot.page.Revision
+    _RequestWrapperT = TypeVar('_RequestWrapperT', bound='api._RequestWrapper')
+

 __all__ = ('APISite', )

 _mw_msg_cache: DefaultDict[str, dict[str, str]] = defaultdict(dict)

-_CompType = Union[int, str, 'pywikibot.page.Page', 'pywikibot.page.Revision']
-_RequestWrapperT = TypeVar('_RequestWrapperT', bound='api._RequestWrapper')
-

 class _OnErrorExc(NamedTuple):
     exception: Exception
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index b6a0d45..75c3d87 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -15,12 +15,7 @@
 from typing import NamedTuple

 import pywikibot
-from pywikibot.backports import (
-    Callable,
-    Container,
-    Iterable,
-    Match,
-)
+from pywikibot.backports import Callable, Container, Iterable, Match
 from pywikibot.backports import OrderedDict as OrderedDictType
 from pywikibot.backports import Pattern
 from pywikibot.backports import Sequence as SequenceType
diff --git a/pywikibot/userinterfaces/__init__.py 
b/pywikibot/userinterfaces/__init__.py
index b4f0f90..8d1b028 100644
--- a/pywikibot/userinterfaces/__init__.py
+++ b/pywikibot/userinterfaces/__init__.py
@@ -14,6 +14,9 @@
 all of which are documented in the abstract class
 :class:`userinterfaces._interface_base.ABUIC`.
 """
+from __future__ import annotations
+
+
 #
 # (C) Pywikibot team, 2008-2022
 #
diff --git a/pywikibot/xmlreader.py b/pywikibot/xmlreader.py
index a01c4d4..ea675a6 100644
--- a/pywikibot/xmlreader.py
+++ b/pywikibot/xmlreader.py
@@ -25,11 +25,8 @@
 except ImportError:
     from xml.etree.ElementTree import iterparse, ParseError

-from pywikibot.backports import Callable, Type
-from pywikibot.tools import (
-    issue_deprecation_warning,
-    open_archive,
-)
+from pywikibot.backports import Callable
+from pywikibot.tools import issue_deprecation_warning, open_archive


 def parseRestrictions(restrictions):
@@ -127,7 +124,7 @@
                  # when allrevisions removed, revisions can default to 'latest'
                  revisions: str = 'first_found',
                  on_error: None | (
-                     Callable[[Type[BaseException]], None]) = None) -> None:
+                     Callable[[type[BaseException]], None]) = None) -> None:
         """Initializer."""
         self.filename = filename
         self.on_error = on_error
diff --git a/scripts/__init__.py b/scripts/__init__.py
index b5d5586..d5724e1 100644
--- a/scripts/__init__.py
+++ b/scripts/__init__.py
@@ -24,6 +24,9 @@
 - find a script even if given script name does not match a filename e.g.
   due to spelling mistake
 """
+from __future__ import annotations
+
+
 #
 # (C) Pywikibot team, 2021-2023
 #
diff --git a/scripts/userscripts/__init__.py b/scripts/userscripts/__init__.py
index f36f2b9..604ed80 100644
--- a/scripts/userscripts/__init__.py
+++ b/scripts/userscripts/__init__.py
@@ -1 +1,3 @@
 """THIS DIRECTORY IS TO HOLD USER-DEFINED BOT SCRIPTS."""
+
+from __future__ import annotations
diff --git a/setup.py b/setup.py
index c5da297..487cb41 100755
--- a/setup.py
+++ b/setup.py
@@ -27,8 +27,10 @@
 import os
 import re
 import sys
+
 from setuptools import setup

+
 if sys.version_info[:3] >= (3, 9):
     List = list
 else:
diff --git a/tests/diff_tests.py b/tests/diff_tests.py
index 2ff9eb8..70c0d06 100755
--- a/tests/diff_tests.py
+++ b/tests/diff_tests.py
@@ -4,6 +4,8 @@
 # (C) Pywikibot team, 2016-2022
 #
 # Distributed under the terms of the MIT license.
+from __future__ import annotations
+
 from contextlib import suppress
 from unittest.mock import patch

diff --git a/tests/i18n/__init__.py b/tests/i18n/__init__.py
index f1a0213..75a747e 100644
--- a/tests/i18n/__init__.py
+++ b/tests/i18n/__init__.py
@@ -1 +1,3 @@
 """Test i18n data package."""
+
+from __future__ import annotations
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 0b16821..c27ac84 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -4,13 +4,14 @@
 # (C) Pywikibot team, 2009-2023
 #
 # Distributed under the terms of the MIT license.
+from __future__ import annotations
+
 import calendar
 import datetime
 import logging
 import sys
 import unittest
 from contextlib import suppress
-from typing import Optional
 from unittest import mock

 import pywikibot
@@ -816,8 +817,7 @@

     """Test item claim filter page generator generator."""

-    def _simple_claim_test(self, prop: str, claim, qualifiers: Optional[dict],
-                           valid: bool, negate: bool = False):
+    def _simple_claim_test(self, prop, claim, qualifiers, valid, negate=False):
         """
         Test given claim on sample (India) page.

diff --git a/tests/pwb/__init__.py b/tests/pwb/__init__.py
index fb493b3..3d1d730 100644
--- a/tests/pwb/__init__.py
+++ b/tests/pwb/__init__.py
@@ -1 +1,3 @@
 """Dummy package initialisation."""
+
+from __future__ import annotations
diff --git a/tests/tests_tests.py b/tests/tests_tests.py
index eed24ef..a007a40 100755
--- a/tests/tests_tests.py
+++ b/tests/tests_tests.py
@@ -4,6 +4,8 @@
 # (C) Pywikibot team, 2014-2023
 #
 # Distributed under the terms of the MIT license.
+from __future__ import annotations
+
 import unittest
 from contextlib import suppress

diff --git a/tests/tools_chars_tests.py b/tests/tools_chars_tests.py
index 0f93120..6e25dff 100755
--- a/tests/tools_chars_tests.py
+++ b/tests/tools_chars_tests.py
@@ -4,6 +4,8 @@
 # (C) Pywikibot team, 2015-2023
 #
 # Distributed under the terms of the MIT license.
+from __future__ import annotations
+
 import unicodedata
 import unittest
 from contextlib import suppress
diff --git a/tests/tools_tests.py b/tests/tools_tests.py
index 8da9e24..4f3d41d 100755
--- a/tests/tools_tests.py
+++ b/tests/tools_tests.py
@@ -4,6 +4,8 @@
 # (C) Pywikibot team, 2015-2023
 #
 # Distributed under the terms of the MIT license.
+from __future__ import annotations
+
 import decimal
 import hashlib
 import os
diff --git a/tox.ini b/tox.ini
index 7eb046e..426168d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -242,7 +242,7 @@

 [isort]
 py_version = 37
-add_imports = ["from __future__ import annotations"]
+add_imports = from __future__ import annotations
 atomic = true
 ensure_newline_before_comments = true
 force_grid_wrap = 0

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/986636
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I60ba68d08f6170cace0ffc1ff685c3783ecbe57d
Gerrit-Change-Number: 986636
Gerrit-PatchSet: 6
Gerrit-Owner: JJMC89 <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to