From cb243895f1c694a4b31e491a0602b2318c74a786 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 31 Oct 2021 04:01:34 +0100 Subject: [PATCH] Fix the `typing_extensions` runtime dependency version (#641) * Only use `typing_extensions` below Python 3.8 * Rely on unconstrained `typing-extensions` version --- proxy/common/types.py | 9 ++++++++- requirements.txt | 2 +- setup.py | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/proxy/common/types.py b/proxy/common/types.py index 279211e422..a95a49e8d2 100644 --- a/proxy/common/types.py +++ b/proxy/common/types.py @@ -10,10 +10,17 @@ """ import queue import ipaddress +import sys from typing import TYPE_CHECKING, Dict, Any, List, Union -from typing_extensions import Protocol +# NOTE: Using try/except causes linting problems which is why it's necessary +# NOTE: to use this mypy/pylint idiom for py36-py38 compatibility +# Ref: https://github.com/python/typeshed/issues/3500#issuecomment-560958608 +if sys.version_info >= (3, 8): + from typing import Protocol +else: + from typing_extensions import Protocol if TYPE_CHECKING: DictQueueType = queue.Queue[Dict[str, Any]] # pragma: no cover diff --git a/requirements.txt b/requirements.txt index 160811c5d3..71f75de866 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -typing-extensions==3.10.0.2 +typing-extensions==3.10.0.2; python_version < "3.8" diff --git a/setup.py b/setup.py index 849de5f856..45ec2d5454 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,9 @@ zip_safe=False, packages=find_packages(exclude=['tests', 'tests.*']), package_data={'proxy': ['py.typed']}, - install_requires=open('requirements.txt', 'r').read().strip().split(), + install_requires=[ + 'typing-extensions; python_version < "3.8"', + ], entry_points={ 'console_scripts': [ 'proxy = proxy:entry_point'