From 502113a24b09929da3dfaf20bfa6f0add3ed62c3 Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Fri, 29 Nov 2019 18:13:26 -0500 Subject: [PATCH 1/5] Always use importlib_metadata to avoid mypy errors --- setup.cfg | 2 +- tox.ini | 3 +-- twine/__init__.py | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index e7b0f741..f089f8f5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ install_requires= requests-toolbelt >= 0.8.0, != 0.9.0 setuptools >= 0.7.0 tqdm >= 4.14 - importlib_metadata; python_version < "3.8" + importlib_metadata keyring >= 15.1 setup_requires = setuptools_scm >= 1.15 diff --git a/tox.ini b/tox.ini index 2d76e7ee..d8315e6f 100644 --- a/tox.ini +++ b/tox.ini @@ -53,8 +53,7 @@ commands = [testenv:lint-mypy] deps = - # pin to workaround #550 - mypy<0.750 + mypy lxml commands = # TODO: Consider checking the tests after the source is fully typed diff --git a/twine/__init__.py b/twine/__init__.py index a07918b1..3fad44d1 100644 --- a/twine/__init__.py +++ b/twine/__init__.py @@ -18,10 +18,10 @@ __copyright__ = "Copyright 2019 Donald Stufft and individual contributors" -try: - import importlib.metadata as importlib_metadata -except ImportError: - import importlib_metadata + +# This should be importlib.metadata in Python 3.8, but a conditional import +# with try/except was causing confusing mypy errors +import importlib_metadata metadata = importlib_metadata.metadata('twine') From 50a389d130c847e695dbe26bb0371ff2719e9db5 Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Fri, 29 Nov 2019 21:08:17 -0500 Subject: [PATCH 2/5] Revert "Always use importlib_metadata to avoid mypy errors" This reverts commit 502113a24b09929da3dfaf20bfa6f0add3ed62c3. --- setup.cfg | 2 +- tox.ini | 3 ++- twine/__init__.py | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/setup.cfg b/setup.cfg index f089f8f5..e7b0f741 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ install_requires= requests-toolbelt >= 0.8.0, != 0.9.0 setuptools >= 0.7.0 tqdm >= 4.14 - importlib_metadata + importlib_metadata; python_version < "3.8" keyring >= 15.1 setup_requires = setuptools_scm >= 1.15 diff --git a/tox.ini b/tox.ini index d8315e6f..2d76e7ee 100644 --- a/tox.ini +++ b/tox.ini @@ -53,7 +53,8 @@ commands = [testenv:lint-mypy] deps = - mypy + # pin to workaround #550 + mypy<0.750 lxml commands = # TODO: Consider checking the tests after the source is fully typed diff --git a/twine/__init__.py b/twine/__init__.py index 3fad44d1..a07918b1 100644 --- a/twine/__init__.py +++ b/twine/__init__.py @@ -18,10 +18,10 @@ __copyright__ = "Copyright 2019 Donald Stufft and individual contributors" - -# This should be importlib.metadata in Python 3.8, but a conditional import -# with try/except was causing confusing mypy errors -import importlib_metadata +try: + import importlib.metadata as importlib_metadata +except ImportError: + import importlib_metadata metadata = importlib_metadata.metadata('twine') From 61fdbe0dba79dc19cda5320a0ad1352facf12d3d Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Fri, 29 Nov 2019 21:09:29 -0500 Subject: [PATCH 3/5] Rework imports and ignore known mypy issues --- twine/__init__.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/twine/__init__.py b/twine/__init__.py index a07918b1..ff640777 100644 --- a/twine/__init__.py +++ b/twine/__init__.py @@ -18,19 +18,22 @@ __copyright__ = "Copyright 2019 Donald Stufft and individual contributors" + try: - import importlib.metadata as importlib_metadata + # https://github.com/python/mypy/issues/1393 + from importlib.metadata import metadata # type: ignore except ImportError: - import importlib_metadata + # https://github.com/python/mypy/issues/1153 + from importlib_metadata import metadata # type: ignore -metadata = importlib_metadata.metadata('twine') +twine_metadata = metadata('twine') -__title__ = metadata['name'] -__summary__ = metadata['summary'] -__uri__ = metadata['home-page'] -__version__ = metadata['version'] -__author__ = metadata['author'] -__email__ = metadata['author-email'] -__license__ = metadata['license'] +__title__ = twine_metadata['name'] +__summary__ = twine_metadata['summary'] +__uri__ = twine_metadata['home-page'] +__version__ = twine_metadata['version'] +__author__ = twine_metadata['author'] +__email__ = twine_metadata['author-email'] +__license__ = twine_metadata['license'] From 66e4166ddad7d6f4e9461e1f4263829e54d3bc83 Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Fri, 29 Nov 2019 21:19:01 -0500 Subject: [PATCH 4/5] Unpin mypy --- tox.ini | 3 +-- twine/__init__.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tox.ini b/tox.ini index 2d76e7ee..d8315e6f 100644 --- a/tox.ini +++ b/tox.ini @@ -53,8 +53,7 @@ commands = [testenv:lint-mypy] deps = - # pin to workaround #550 - mypy<0.750 + mypy lxml commands = # TODO: Consider checking the tests after the source is fully typed diff --git a/twine/__init__.py b/twine/__init__.py index ff640777..a7f6c955 100644 --- a/twine/__init__.py +++ b/twine/__init__.py @@ -18,13 +18,12 @@ __copyright__ = "Copyright 2019 Donald Stufft and individual contributors" - try: - # https://github.com/python/mypy/issues/1393 from importlib.metadata import metadata # type: ignore + # https://github.com/python/mypy/issues/1393 except ImportError: - # https://github.com/python/mypy/issues/1153 from importlib_metadata import metadata # type: ignore + # https://github.com/python/mypy/issues/1153 twine_metadata = metadata('twine') From 42358371a75dd9e192359807e2f22f86a1a221d4 Mon Sep 17 00:00:00 2001 From: Brian Rutledge Date: Mon, 2 Dec 2019 18:20:30 -0500 Subject: [PATCH 5/5] Use version check instead of try/except --- twine/__init__.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/twine/__init__.py b/twine/__init__.py index a7f6c955..d54766f0 100644 --- a/twine/__init__.py +++ b/twine/__init__.py @@ -18,21 +18,21 @@ __copyright__ = "Copyright 2019 Donald Stufft and individual contributors" -try: - from importlib.metadata import metadata # type: ignore - # https://github.com/python/mypy/issues/1393 -except ImportError: - from importlib_metadata import metadata # type: ignore - # https://github.com/python/mypy/issues/1153 +import sys +if sys.version_info[:2] >= (3, 8): + import importlib.metadata as importlib_metadata +else: + import importlib_metadata -twine_metadata = metadata('twine') +metadata = importlib_metadata.metadata('twine') -__title__ = twine_metadata['name'] -__summary__ = twine_metadata['summary'] -__uri__ = twine_metadata['home-page'] -__version__ = twine_metadata['version'] -__author__ = twine_metadata['author'] -__email__ = twine_metadata['author-email'] -__license__ = twine_metadata['license'] + +__title__ = metadata['name'] +__summary__ = metadata['summary'] +__uri__ = metadata['home-page'] +__version__ = metadata['version'] +__author__ = metadata['author'] +__email__ = metadata['author-email'] +__license__ = metadata['license']