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

Change subject: [4.0] Remove Python 2 code from pywikibot/__init__.py
......................................................................

[4.0] Remove Python 2 code from pywikibot/__init__.py

- reorder imports
- remove deprecation Warning
- replace UnicodeType by str

Bug: T213287
Bug: T239542
Change-Id: I93b45567914aae1b5aef332d8598194182816df1
---
M pywikibot/__init__.py
M tests/utils.py
2 files changed, 7 insertions(+), 38 deletions(-)

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



diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 472ac7d..b88303e 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -5,17 +5,16 @@
 #
 # Distributed under the terms of the MIT license.
 #
-from __future__ import absolute_import, division, unicode_literals
-
 import atexit
 import datetime
-from decimal import Decimal
 import math
 import re
-import sys
 import threading
 import time

+from contextlib import suppress
+from decimal import Decimal
+from queue import Queue
 from warnings import warn

 from pywikibot.__metadata__ import (
@@ -66,19 +65,11 @@
     MediaWikiVersion as _MediaWikiVersion,
     redirect_func,
     ModuleDeprecationWrapper as _ModuleDeprecationWrapper,
-    PY2, PYTHON_VERSION,
     UnicodeMixin,
-    UnicodeType
 )
 from pywikibot.tools.formatter import color_format


-if not PY2:
-    from queue import Queue
-else:
-    from Queue import Queue
-
-
 textlib_methods = (
     'categoryFormat', 'compileLinkR', 'extract_templates_and_params',
     'getCategoryLinks', 'getLanguageLinks', 'interwikiFormat', 'interwikiSort',
@@ -114,19 +105,6 @@
 )
 __all__ += textlib_methods

-if PY2:
-    # T111615: Python 2 requires __all__ is bytes
-    globals()['__all__'] = tuple(bytes(item) for item in __all__)
-
-if PY2 or PYTHON_VERSION < (3, 5, 0):
-    warn("""
-
-Python {version} will be dropped soon.
-It is recommended to use Python 3.5 or above.
-See {what} for further information.
-""".format(version=sys.version.split(None, 1)[0],
-           what='T213287' if PY2 else 'T239542'),
-         FutureWarning)  # probably adjust the line no in utils.execute()

 for _name in textlib_methods:
     target = getattr(textlib, _name)
@@ -795,7 +773,7 @@
         self.site = site or Site().data_repository()

         # also allow entity URIs to be provided via unit parameter
-        if isinstance(unit, UnicodeType) and \
+        if isinstance(unit, str) and \
                 unit.partition('://')[0] not in ('http', 'https'):
             raise ValueError("'unit' must be an ItemPage or entity uri.")

@@ -837,7 +815,7 @@
         @type lazy_load: bool
         @return: pywikibot.ItemPage
         """
-        if not isinstance(self._unit, UnicodeType):
+        if not isinstance(self._unit, str):
             return self._unit

         repo = repo or self.site
@@ -1254,8 +1232,6 @@

     if not isinstance(interface, type):
         # If it isn't a class, assume it is a string
-        if PY2:  # Must not be unicode in Python 2
-            interface = str(interface)
         try:
             tmp = __import__('pywikibot.site', fromlist=[interface])
         except ImportError:
@@ -1389,11 +1365,9 @@
                 return

     # only need one drop() call because all throttles use the same global pid
-    try:
+    with suppress(IndexError):
         list(_sites.values())[0].throttle.drop()
         log('Dropped throttle(s).')
-    except IndexError:
-        pass


 atexit.register(_flush)
@@ -1417,10 +1391,8 @@
     if not _putthread.is_alive():
         try:
             page_put_queue.mutex.acquire()
-            try:
+            with suppress(AssertionError, RuntimeError):
                 _putthread.start()
-            except (AssertionError, RuntimeError):
-                pass
         finally:
             page_put_queue.mutex.release()
     page_put_queue.put((request, args, kwargs))
diff --git a/tests/utils.py b/tests/utils.py
index e1fd429..e1d9075 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -28,7 +28,6 @@
 from pywikibot.data.api import CachedRequest, APIError
 from pywikibot.data.api import Request as _original_Request
 from pywikibot.site import Namespace
-from pywikibot.tools import PY2, PYTHON_VERSION
 from tests import _pwb_py, unittest


@@ -574,8 +573,6 @@
     @param command: executable to run and arguments to use
     @type command: list of str
     """
-    if PY2 or PYTHON_VERSION < (3, 5, 0):
-        command.insert(1, '-W ignore::FutureWarning:pywikibot:131')
     if cryptography_version and cryptography_version < [1, 3, 4]:
         command.insert(1, '-W ignore:Old version of cryptography:Warning')


--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/610791
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: I93b45567914aae1b5aef332d8598194182816df1
Gerrit-Change-Number: 610791
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Zhuyifei1999 <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to