jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1200467?usp=email )
Change subject: cleanup: replace collections from backports collections classes
......................................................................
cleanup: replace collections from backports collections classes
Bug: T401802
Change-Id: I9db4dd970aef279edb4e07fdcd3d79bb09d32c01
---
M pywikibot/backports.py
M pywikibot/config.py
M pywikibot/family.py
M pywikibot/site/_apisite.py
M pywikibot/textlib.py
M pywikibot/throttle.py
M scripts/delete.py
7 files changed, 11 insertions(+), 30 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/backports.py b/pywikibot/backports.py
index 8ece3db..a0816f2 100644
--- a/pywikibot/backports.py
+++ b/pywikibot/backports.py
@@ -23,24 +23,10 @@
PYTHON_VERSION: tuple[int, int, int] = sys.version_info[:3]
SPHINX_RUNNING: bool = 'sphinx' in sys.modules
-# typing
-if PYTHON_VERSION < (3, 9):
- from typing import DefaultDict # type: ignore[misc]
-else:
- from collections import ( # type: ignore[misc] # noqa: N812
- defaultdict as DefaultDict,
- )
-
-
-if PYTHON_VERSION < (3, 9):
- from typing import OrderedDict
-else:
- from collections import OrderedDict
if PYTHON_VERSION < (3, 9):
from typing import (
Container,
- Counter,
Generator,
Iterable,
Iterator,
@@ -48,7 +34,6 @@
Sequence,
)
else:
- from collections import Counter
from collections.abc import (
Container,
Generator,
diff --git a/pywikibot/config.py b/pywikibot/config.py
index 18ea53c..0cf0192 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -56,12 +56,12 @@
from zipfile import ZipFile, is_zipfile
from pywikibot.__metadata__ import __version__ as pwb_version
-from pywikibot.backports import DefaultDict, Mapping
+from pywikibot.backports import Mapping
from pywikibot.logging import error, info, warning
if TYPE_CHECKING:
- _DabComDict = DefaultDict[str, dict[str, str]]
+ _DabComDict = collections.defaultdict[str, dict[str, str]]
_ValueType = TypeVar('_ValueType')
diff --git a/pywikibot/family.py b/pywikibot/family.py
index c3cdef6..74e88a2 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -22,7 +22,7 @@
import pywikibot
from pywikibot import config
-from pywikibot.backports import DefaultDict, Mapping, Sequence
+from pywikibot.backports import Mapping, Sequence
from pywikibot.data import wikistats
from pywikibot.exceptions import FamilyMaintenanceWarning, UnknownFamilyError
from pywikibot.tools import classproperty, deprecated
@@ -31,7 +31,7 @@
logger = logging.getLogger('pywiki.wiki.family')
if TYPE_CHECKING:
- CrossnamespaceType = DefaultDict[str, dict[str, list[int]]]
+ CrossnamespaceType = collections.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/site/_apisite.py b/pywikibot/site/_apisite.py
index 51bfe59..0361728 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -18,8 +18,7 @@
import pywikibot
from pywikibot import login
-from pywikibot.backports import DefaultDict, Iterable
-from pywikibot.backports import OrderedDict as OrderedDictType
+from pywikibot.backports import Iterable
from pywikibot.comms import http
from pywikibot.data import api
from pywikibot.exceptions import (
@@ -90,7 +89,7 @@
__all__ = ('APISite', )
-_mw_msg_cache: DefaultDict[str, dict[str, str]] = defaultdict(dict)
+_mw_msg_cache: defaultdict[str, dict[str, str]] = defaultdict(dict)
class _OnErrorExc(NamedTuple):
@@ -963,7 +962,7 @@
self,
keys: Iterable[str],
lang: str | None = None
- ) -> OrderedDictType[str, str]:
+ ) -> OrderedDict[str, str]:
"""Fetch the text of a set of MediaWiki messages.
The returned dict uses each key to store the associated message.
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 19d074d..c1c56a6 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -18,7 +18,6 @@
import pywikibot
from pywikibot.backports import Callable, Container, Iterable
-from pywikibot.backports import OrderedDict as OrderedDictType
from pywikibot.backports import Sequence as SequenceType
from pywikibot.backports import pairwise
from pywikibot.exceptions import InvalidTitleError, SiteDefinitionError
@@ -2018,7 +2017,7 @@
text: str,
remove_disabled_parts: bool = False,
strip: bool = False,
-) -> list[tuple[str, OrderedDictType[str, str]]]:
+) -> list[tuple[str, OrderedDict[str, str]]]:
"""Return a list of templates found in text.
Return value is a list of tuples. There is one tuple for each use of a
diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py
index eb270fb..a106eaf 100644
--- a/pywikibot/throttle.py
+++ b/pywikibot/throttle.py
@@ -26,7 +26,6 @@
import pywikibot
from pywikibot import config
-from pywikibot.backports import Counter as CounterType
from pywikibot.tools import deprecated, deprecated_args, deprecated_signature
@@ -92,7 +91,7 @@
self.retry_after = 0 # set by http.request
self.delay = 0
self.checktime = 0.0
- self.modules: CounterType[str] = Counter()
+ self.modules: Counter[str] = Counter()
self.checkMultiplicity()
self.set_delays()
diff --git a/scripts/delete.py b/scripts/delete.py
index bc9ae09..b18e82f 100755
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -52,7 +52,7 @@
python pwb.py delete -cat:"To delete" -always
"""
#
-# (C) Pywikibot team, 2013-2024
+# (C) Pywikibot team, 2013-2025
#
# Distributed under the terms of the MIT license.
#
@@ -62,7 +62,6 @@
import pywikibot
from pywikibot import i18n, pagegenerators
-from pywikibot.backports import DefaultDict
from pywikibot.bot import CurrentPageBot
from pywikibot.page import Page
from pywikibot.site import Namespace
@@ -73,7 +72,7 @@
# with the parameter -help.
docuReplacements = {'¶ms;': pagegenerators.parameterHelp} # noqa: N816
-RefTable = DefaultDict[Namespace, Page]
+RefTable = collections.defaultdict[Namespace, Page]
class PageWithRefs(Page):
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1200467?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I9db4dd970aef279edb4e07fdcd3d79bb09d32c01
Gerrit-Change-Number: 1200467
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]