jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[fix] typing Dict, List, Set, Tuple are deprecated in Python 3.9

Use buildins instead

Change-Id: I74108dfb262f2895a1570ff9f1bab2bcd41fad19
---
M generate_user_files.py
M pywikibot/bot.py
M pywikibot/comms/http.py
M pywikibot/comms/threadedhttp.py
M pywikibot/config2.py
M pywikibot/data/api.py
M pywikibot/family.py
M pywikibot/i18n.py
M pywikibot/logentries.py
M pywikibot/page/__init__.py
M pywikibot/pagegenerators.py
M pywikibot/plural.py
M pywikibot/site/__init__.py
M pywikibot/textlib.py
M pywikibot/userinterfaces/gui.py
15 files changed, 105 insertions(+), 20 deletions(-)

diff --git a/generate_user_files.py b/generate_user_files.py
index 7d5a7bf..b2b7e51 100755
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -11,13 +11,18 @@
import re
import sys

-from typing import Optional, Tuple
+from typing import Optional

from collections import namedtuple
from textwrap import fill

from generate_family_file import _import_with_no_user_config

+if sys.version_info[:2] >= (3, 9):
+ Tuple = tuple
+else:
+ from typing import Tuple
+

# DISABLED_SECTIONS cannot be copied; variables must be set manually
DISABLED_SECTIONS = {'USER INTERFACE SETTINGS', # uses sys
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 746be8e..21bd532 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -99,7 +99,7 @@
from importlib import import_module
from pathlib import Path
from textwrap import fill
-from typing import Any, Dict, Optional, Union
+from typing import Any, Optional, Union
from warnings import warn

import pywikibot
@@ -130,6 +130,11 @@
from pywikibot.tools import classproperty, suppress_warnings
from pywikibot.tools.formatter import color_format

+if PYTHON_VERSION >= (3, 9):
+ Dict = dict
+else:
+ from typing import Dict
+
# Note: all output goes through python std library "logging" module
_logger = 'bot'

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 9793d83..ef9cb6e 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -21,7 +21,7 @@

from http import cookiejar
from string import Formatter
-from typing import Optional, Tuple, Union
+from typing import Optional, Union
from urllib.parse import quote, urlparse
from warnings import warn

@@ -39,8 +39,14 @@
deprecate_arg,
file_mode_checker,
issue_deprecation_warning,
+ PYTHON_VERSION,
)

+if PYTHON_VERSION >= (3, 9):
+ Tuple = tuple
+else:
+ from typing import Tuple
+
try:
import requests_oauthlib
except ImportError as e:
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index 7148768..572f2c4 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -8,12 +8,16 @@
import codecs
import re

-from typing import Dict, Optional
+from typing import Optional
from urllib.parse import urlparse

import pywikibot
-from pywikibot.tools import deprecated, deprecated_args
+from pywikibot.tools import deprecated, deprecated_args, PYTHON_VERSION

+if PYTHON_VERSION >= (3, 9):
+ Dict = dict
+else:
+ from typing import Dict

_logger = 'comms.threadedhttp'

diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index f65d25e..120b404 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -48,12 +48,19 @@
from locale import getdefaultlocale
from os import getenv, environ
from textwrap import fill
-from typing import Dict, List, Optional, Tuple
+from typing import Optional
from warnings import warn

from pywikibot.__metadata__ import __version__ as pwb_version
from pywikibot.logging import error, output, warning
-from pywikibot.tools import issue_deprecation_warning
+from pywikibot.tools import issue_deprecation_warning, PYTHON_VERSION
+
+if PYTHON_VERSION >= (3, 9):
+ Dict = dict
+ List = list
+ Tuple = tuple
+else:
+ from typing import Dict, List, Tuple

OSWIN32 = (sys.platform == 'win32')

diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 00f7f38..a83b72e 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -22,7 +22,7 @@
from email.mime.nonmultipart import MIMENonMultipart
from inspect import getfullargspec
from io import BytesIO
-from typing import Optional, Set, Tuple, Union
+from typing import Optional, Union
from warnings import warn
from urllib.parse import urlencode, unquote

@@ -42,6 +42,12 @@
)
from pywikibot.tools.formatter import color_format

+if PYTHON_VERSION >= (3, 9):
+ Set = set
+ Tuple = tuple
+else:
+ from typing import Set, Tuple
+

_logger = 'data.api'

diff --git a/pywikibot/family.py b/pywikibot/family.py
index b82167b..83f9327 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -16,16 +16,23 @@
from importlib import import_module
from itertools import chain
from os.path import basename, dirname, splitext
-from typing import Dict, List, Optional, Tuple
+from typing import Optional

import pywikibot
from pywikibot import config
from pywikibot.exceptions import UnknownFamily, FamilyMaintenanceWarning
from pywikibot.tools import (
- deprecated, deprecated_args, remove_last_args, issue_deprecation_warning,
- ModuleDeprecationWrapper, FrozenDict, classproperty,
+ classproperty, deprecated, deprecated_args, FrozenDict,
+ issue_deprecation_warning, ModuleDeprecationWrapper, PYTHON_VERSION,
+ remove_last_args,
)

+if PYTHON_VERSION >= (3, 9):
+ Dict = dict
+ List = list
+ Tuple = tuple
+else:
+ from typing import Dict, List, Tuple

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

diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index b60f761..7107f96 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -30,7 +30,7 @@
from collections import defaultdict
from contextlib import suppress
from textwrap import fill
-from typing import List, Optional
+from typing import Optional
from warnings import warn

import pywikibot
@@ -44,8 +44,10 @@

if PYTHON_VERSION >= (3, 9, 0):
from functools import cache
+ List = list
else:
from functools import lru_cache
+ from typing import List
cache = lru_cache(None)

PLURAL_PATTERN = r'{{PLURAL:(?:%\()?([^\)]*?)(?:\)d)?\|(.*?)}}'
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index 1015ea9..683ba39 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -6,11 +6,16 @@
# Distributed under the terms of the MIT license.
#
from collections import UserDict
-from typing import List, Optional
+from typing import Optional

import pywikibot
from pywikibot.exceptions import Error, HiddenKeyError
-from pywikibot.tools import deprecated, classproperty
+from pywikibot.tools import classproperty, deprecated, PYTHON_VERSION
+
+if PYTHON_VERSION >= (3, 9):
+ List = list
+else:
+ from typing import List

_logger = 'wiki'

diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index a528733..2c89dd1 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -27,7 +27,7 @@
from contextlib import suppress
from html.entities import name2codepoint
from itertools import chain
-from typing import Any, Dict, List, Optional, Union
+from typing import Any, Optional, Union
from urllib.parse import quote_from_bytes, unquote_to_bytes
from warnings import warn

@@ -55,11 +55,18 @@
first_upper,
issue_deprecation_warning,
manage_wrapping,
+ PYTHON_VERSION,
redirect_func,
remove_last_args,
)
from pywikibot.tools import is_IP

+if PYTHON_VERSION >= (3, 9):
+ Dict = dict
+ List = list
+else:
+ from typing import Dict, List
+

PROTOCOL_REGEX = r'\Ahttps?://'

diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index dbe59c6..a0cc6c8 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -31,7 +31,7 @@
from functools import partial
from itertools import zip_longest
from requests.exceptions import ReadTimeout
-from typing import List, Optional, Union
+from typing import Optional, Union

import pywikibot

@@ -52,7 +52,12 @@
from pywikibot.data import api
from pywikibot.exceptions import ServerError, UnknownExtension
from pywikibot.proofreadpage import ProofreadPage
+from pywikibot.tools import PYTHON_VERSION

+if PYTHON_VERSION >= (3, 9):
+ List = list
+else:
+ from typing import List

_logger = 'pagegenerators'

diff --git a/pywikibot/plural.py b/pywikibot/plural.py
index 5dea038..515c916 100644
--- a/pywikibot/plural.py
+++ b/pywikibot/plural.py
@@ -5,7 +5,15 @@
#
# Distributed under the terms of the MIT license.
#
-from typing import Callable, Dict, Union
+import sys
+
+from typing import Callable, Union
+
+if sys.version_info[:2] >= (3, 9):
+ Dict = dict
+else:
+ from typing import Dict
+

PluralRule = Dict[str, Union[int, Callable]]

diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index f4408a1..4ef3142 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -29,7 +29,7 @@
from itertools import zip_longest
from pywikibot.login import LoginStatus as _LoginStatus
from textwrap import fill
-from typing import List, Optional, Union
+from typing import Optional, Union
from warnings import warn

import pywikibot
@@ -84,11 +84,17 @@
merge_unique_dicts,
ModuleDeprecationWrapper,
normalize_username,
+ PYTHON_VERSION,
remove_last_args,
SelfCallMixin,
SelfCallString,
)

+if PYTHON_VERSION >= (3, 9):
+ List = list
+else:
+ from typing import List
+
__all__ = ('APISite', 'DataSite', 'LoginStatus', 'Namespace',
'NamespacesDict', 'PageInUse', 'RemovedSite',
'Siteinfo', 'TokenWallet')
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index e495ca2..471357f 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -18,7 +18,7 @@
from collections import OrderedDict, namedtuple
from contextlib import suppress
from html.parser import HTMLParser
-from typing import List, NamedTuple, Optional, Tuple, Union
+from typing import NamedTuple, Optional, Union

import pywikibot
from pywikibot.exceptions import InvalidTitle, SiteDefinitionError
@@ -27,8 +27,15 @@
deprecate_arg,
deprecated,
issue_deprecation_warning,
+ PYTHON_VERSION,
)

+if PYTHON_VERSION >= (3, 9):
+ List = list
+ Tuple = tuple
+else:
+ from typing import List, Tuple
+
try:
import mwparserfromhell
except ImportError as e:
diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py
index 98b7a88..a32fa11 100644
--- a/pywikibot/userinterfaces/gui.py
+++ b/pywikibot/userinterfaces/gui.py
@@ -12,7 +12,7 @@
import tkinter
from tkinter.scrolledtext import ScrolledText
from tkinter import simpledialog as tkSimpleDialog
-from typing import Optional, Tuple
+from typing import Optional

import pywikibot
from pywikibot import __url__
@@ -34,6 +34,11 @@
from idlelib.configHandler import idleConf
from idlelib.MultiCall import MultiCallCreator

+if PYTHON_VERSION >= (3, 9):
+ Tuple = tuple
+else:
+ from typing import Tuple
+

class TextEditor(ScrolledText):


To view, visit change 634843. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I74108dfb262f2895a1570ff9f1bab2bcd41fad19
Gerrit-Change-Number: 634843
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Isaacandy <isaac@iznd.xyz>
Gerrit-Reviewer: Siebrand <siebrand@kitano.nl>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged