Skip to content

Commit

Permalink
[9.0] Drop support for Python 3.6
Browse files Browse the repository at this point in the history
- drop Python 3.6 support
- add __future__.annotation to enable forward references
  of type hints

Bug: T347026
Change-Id: I7ccd63e41fb8448c724803ef2583844c35a13000
  • Loading branch information
xqt committed Dec 5, 2023
1 parent 7894650 commit 39906ef
Show file tree
Hide file tree
Showing 298 changed files with 643 additions and 232 deletions.
12 changes: 8 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ environment:

matrix:

# Test the lowest supported release of each major Python version
# TODO: Python 3.7.0
# Test the lowest supported release
# Python 3.7.0 is provided by VS 2013

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
PYTHON: "C:\\Python37"
PYTHON_VERSION: "3.7.0"
PYTHON_ARCH: "32"


# AppVeyor pre-installs these versions onto build machines
Expand Down Expand Up @@ -53,11 +57,11 @@ init:
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"

install:
# ignore SSL error for old image
- if [%PYTHON_VERSION%]==[3.7.0] set GIT_SSL_NO_VERIFY=true
- git submodule update --init
# Download the AppVeyor Python build accessories into subdirectory .\appveyor
- mkdir appveyor
# Download Python 3.7.0 which isn't pre-installed
# - ps: ./appveyor_install.ps1
- python --version
- python -c "import platform; print(platform.machine())"
- python -c "import struct; print('PYTHON_ARCH:', struct.calcsize('P') << 3)"
Expand Down
133 changes: 0 additions & 133 deletions appveyor_install.ps1

This file was deleted.

6 changes: 1 addition & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ system that has a compatible version of Python installed. To check
whether you have Python installed and to find its version, just type
``python`` at the CMD or shell prompt.

Python 3.6.1 or higher is currently required to run the bot, but Python 3.7
or higher is recommended. Python 3.6 support will be dropped with Pywikibot 9.

.. attention:: Due to a security vulnerability it is strictly recommended to
use Python 3.7 or higher. Python 3.6 support will be dropped soon.
Python 3.7 or higher is currently required to run the bot.

Pywikibot and this documentation are licensed under the
:ref:`MIT license`;
Expand Down
4 changes: 3 additions & 1 deletion make_dist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Script to create a new distribution. Requires Python 3.7+.
"""Script to create a new distribution.
The following options are supported:
Expand Down Expand Up @@ -50,6 +50,8 @@
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

import abc
import shutil
import sys
Expand Down
4 changes: 2 additions & 2 deletions pwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
Pywikibot is not available on:
{version}
This version of Pywikibot only supports Python 3.6.1+.
This version of Pywikibot only supports Python 3.7+.
"""


def python_is_supported():
"""Check that Python is supported."""
return sys.version_info[:3] >= (3, 6, 1)
return sys.version_info[:3] >= (3, 7)


if not python_is_supported(): # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion pywikibot/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ are not installed by default on some Linux distributions:
* python-tkinter (optional, used by some experimental GUI stuff)


You need to have at least Python version `3.6.1 <https://www.python.org/downloads/>`_
You need to have at least Python version `3.7 <https://www.python.org/downloads/>`_
or newer installed on your computer to be able to run any of the code in this
package. Please refer the manual at mediawiki for further details and
restrictions.
Expand Down
14 changes: 3 additions & 11 deletions pywikibot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

import atexit
import datetime
import re
Expand Down Expand Up @@ -74,7 +76,7 @@
)
from pywikibot.time import Timestamp
from pywikibot.site import APISite, BaseSite
from pywikibot.tools import PYTHON_VERSION, normalize_username
from pywikibot.tools import normalize_username


__all__ = (
Expand All @@ -100,16 +102,6 @@

_sites: Dict[str, APISite] = {}

if PYTHON_VERSION < (3, 7):
warn("""
Python {version} will be dropped soon with Pywikibot 9.0
due to vulnerability security alerts.
It is recommended to use Python 3.7 or above.
See T347026 for further information.
""".format(version=sys.version.split(maxsplit=1)[0]),
FutureWarning) # adjust this line no in utils.execute()


@cache
def _code_fam_from_url(url: str, name: Optional[str] = None
Expand Down
2 changes: 2 additions & 0 deletions pywikibot/__metadata__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

from time import strftime


Expand Down
2 changes: 2 additions & 0 deletions pywikibot/_wbtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

import abc
import datetime
import json
Expand Down
51 changes: 19 additions & 32 deletions pywikibot/backports.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
"""This module contains backports to support older Python versions."""
"""This module contains backports to support older Python versions.
.. deprecated:: 9.0
The *nullcontext* context manager; use ``contextlib.nullcontext``
instead. The *SimpleQueue* queue; use ``queue.SimpleQueue`` instead.
"""
#
# (C) Pywikibot team, 2014-2023
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

import sys
from typing import Any

Expand All @@ -19,37 +26,6 @@
cache = _lru_cache(None)


# context
if PYTHON_VERSION < (3, 7) or SPHINX_RUNNING:

class nullcontext: # noqa: N801

"""Context manager that does no additional processing.
.. seealso:: :python:`contextlib.nullcontext
<library/contextlib.html#contextlib.nullcontext>`,
backported from Python 3.7.
"""

def __init__(self, enter_result: Any = None) -> None: # noqa: D107
self.enter_result = enter_result

def __enter__(self) -> Any:
return self.enter_result

def __exit__(self, *excinfo: Any) -> None:
pass
else:
from contextlib import nullcontext # type: ignore[assignment]


# queue
if PYTHON_VERSION < (3, 7):
from queue import Queue as SimpleQueue
else:
from queue import SimpleQueue # type: ignore[assignment]


# typing
if PYTHON_VERSION < (3, 9):
from typing import DefaultDict # type: ignore[misc]
Expand Down Expand Up @@ -206,3 +182,14 @@ def batched(iterable, n: int) -> Generator[tuple, None, None]:
yield tuple(group)
else:
from itertools import batched # type: ignore[no-redef]


# import ModuleDeprecationWrapper here to prevent circular import
from pywikibot.tools import ModuleDeprecationWrapper # noqa: E402
wrapper = ModuleDeprecationWrapper(__name__)
wrapper.add_deprecated_attr('nullcontext',
replacement_name='contextlib.nullcontext',
since='9.0.0')
wrapper.add_deprecated_attr('SimpleQueue',
replacement_name='queue.SimpleQueue',
since='9.0.0')
2 changes: 2 additions & 0 deletions pywikibot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class is mainly used for bots which work with Wikibase or together
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

__all__ = (
'CRITICAL', 'ERROR', 'INFO', 'WARNING', 'DEBUG', 'INPUT', 'STDOUT',
'VERBOSE', 'critical', 'debug', 'error', 'exception', 'log', 'warning',
Expand Down
2 changes: 2 additions & 0 deletions pywikibot/bot_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

import re
from abc import ABC, abstractmethod
from textwrap import fill
Expand Down
2 changes: 2 additions & 0 deletions pywikibot/comms/eventstreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

import json
from functools import partial
from typing import Optional
Expand Down
2 changes: 2 additions & 0 deletions pywikibot/comms/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

import atexit
import codecs
import re
Expand Down
2 changes: 2 additions & 0 deletions pywikibot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

import collections
import copy
import os
Expand Down
2 changes: 2 additions & 0 deletions pywikibot/cosmetic_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations

import re
from contextlib import suppress
from enum import IntEnum
Expand Down
Loading

0 comments on commit 39906ef

Please sign in to comment.