From afc9b54cdbc5c6cc60cddc7ec41d235fc0ef7e6a Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Fri, 27 Jan 2023 16:32:50 +0000 Subject: [PATCH] Drop Python 3.7 or earlier support --- docs/changes.rst | 4 ++++ mypy.ini | 8 ++++---- setup.cfg | 12 +++++------- tests/datavalue_test.py | 4 ++-- tox.ini | 17 ++++++++++------- wikidata/entity.py | 2 +- wikidata/multilingual.py | 18 ++++++++++++++---- 7 files changed, 40 insertions(+), 25 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 8712b70..924cb04 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -6,11 +6,15 @@ Version 0.8.0 To be released. +- Python 3.4---3.7 are no more supported. The minimum supported Python version + is Python 3.8. Instead, now it's tested with Python 3.8---3.11. - :class:`~wikidata.entity.Entity` and :class:`~wikidata.client.Client` became possible to be serialized using :mod:`pickle`. [:issue:`31`] - Fixed a typing bug that :attr:`Entity.label ` and :attr:`Entity.description ` properties were incorrectly typed. +- :class:`wikidata.multilingual.MultilingualText`'s constructor became to take + only :class:`Locale` for parameter ``locale``. Version 0.7.0 diff --git a/mypy.ini b/mypy.ini index 54aba60..e37ec0c 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,13 +1,13 @@ [mypy] -python_version = 3.5 +python_version = 3.8 check_untyped_defs = true follow_imports = silent -show_none_errors = true strict_optional = true warn_unused_ignores = true +scripts_are_modules = true [mypy-tests.*] check_untyped_defs = false +warn_unused_ignores = false -[mypy-pytest.*] -ignore_missing_imports = true +[mypy-pytest.*] \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index a4e49ff..357de9a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -51,15 +51,13 @@ wikidata = [options.extras_require] tests = - flake8 >= 3.8.3 + flake8 >= 6.0.0 flake8-import-order-spoqa - pytest ~= 4.6.11 - pytest-flake8 ~= 1.0.6 -mypy = - mypy >= 0.782 + pytest ~= 7.2.1 + mypy >= 0.991 [tool:pytest] -addopts = --ff --doctest-glob=*.rst --doctest-modules --flake8 +addopts = --ff --doctest-glob=*.rst --doctest-modules testpaths = tests wikidata @@ -70,6 +68,6 @@ doctest_optionflags = ELLIPSIS [flake8] -exclude = .tox,docs,typeshed +exclude = .tox,build,dist,docs,typeshed import-order-style = spoqa application-import-names = wikidata, tests diff --git a/tests/datavalue_test.py b/tests/datavalue_test.py index 7745e5e..be76ecf 100644 --- a/tests/datavalue_test.py +++ b/tests/datavalue_test.py @@ -8,7 +8,7 @@ from wikidata.datavalue import DatavalueError, Decoder from wikidata.entity import Entity, EntityId from wikidata.globecoordinate import GlobeCoordinate -from wikidata.multilingual import MonolingualText +from wikidata.multilingual import Locale, MonolingualText from wikidata.quantity import Quantity @@ -145,7 +145,7 @@ def test_decoder_monolingualtext(fx_client: Client): 'language': 'ko', 'text': '윤동주', }, - }) == MonolingualText('윤동주', 'ko') + }) == MonolingualText('윤동주', Locale('ko')) def test_decoder_commonsMedia__string(fx_client: Client): diff --git a/tox.ini b/tox.ini index 0eba1b2..49d78a9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,25 +1,28 @@ [tox] envlist = # CHECK If you're going to change the list of supported Python versions - # update .travis.yml and setup.py's classifiers as well. - py34, py35, py36, py37, py38, pypy3, mypy + # update .travis.yml, .devcontainer/devcontainer.json, and setup.cfg's + # classifiers as well. + py38, py39, py310, py311, pypy3, mypy, flake8 [testenv] extras = tests -pip_version = pip commands = pytest {posargs:} -[testenv:py34] -pip_version = pip < 19.2 - [testenv:mypy] -extras = mypy +extras = tests basepython = python3 commands = mypy -p wikidata mypy -p tests +[testenv:flake8] +extras = tests +basepython = python3 +commands = + flake8 + [testenv:docs] basepython = python3 deps = diff --git a/wikidata/entity.py b/wikidata/entity.py index 87ae347..e5ac06e 100644 --- a/wikidata/entity.py +++ b/wikidata/entity.py @@ -172,7 +172,7 @@ class Entity(collections.abc.Mapping, collections.abc.Hashable): def __init__(self, id: EntityId, client: 'Client') -> None: self.id = id self.client = client - self.data = None # type: Optional[Mapping[str, object]] + self.data: Optional[Mapping[str, object]] = None self.state = EntityState.not_loaded # type: EntityState def __eq__(self, other) -> bool: diff --git a/wikidata/multilingual.py b/wikidata/multilingual.py index 0d5ba4d..b64cef2 100644 --- a/wikidata/multilingual.py +++ b/wikidata/multilingual.py @@ -3,7 +3,7 @@ """ import collections.abc -from typing import Iterator, Mapping, NewType, Type, Union +from typing import Iterator, Mapping, NewType, Type, Union, cast __all__ = 'Locale', 'MonolingualText', 'MultilingualText' @@ -59,15 +59,25 @@ class MonolingualText(str): Locale-denoted text. It's almost equivalent to :class:`str` (and indeed subclasses :class:`str`) except that it has an extra attribute, :attr:`locale`, that denotes what language the text is written in. + + .. versionchanged:: 0.8.0 + + The type hint of the constructor's ``locale`` parameter became + :class:`Locale`. + """ #: (:class:`Locale`) The code of :attr:`locale`. - locale = None # type: Locale + #: + #: .. versionchanged:: 0.7.0 + #: + #: The type became :class:`Locale` (was :class:`babel.core.Locale`). + locale: Locale def __new__(cls: Type[str], text: str, - locale: Union[Locale, str]) -> 'MonolingualText': - self = str.__new__(cls, text) # type: ignore + locale: Locale) -> 'MonolingualText': + self = cast(MonolingualText, str.__new__(cls, text)) self.locale = locale return self