diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2022-02-13 19:10:06 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-13 19:10:06 -0800 |
commit | 83ed5bfb8e06033f1b1e92df454da6d0d26e1474 (patch) | |
tree | 434de2f7fbcee1c728c887df1b5b24b180101aed | |
parent | 16cf672885bbf1dfb44914b9f0f50929380b7b41 (diff) | |
download | typing-83ed5bfb8e06033f1b1e92df454da6d0d26e1474.tar.gz |
Fix Python 3.7.1 and run more versions in CI (#1076)
-rw-r--r-- | .github/workflows/ci.yml | 6 | ||||
-rw-r--r-- | typing_extensions/CHANGELOG | 5 | ||||
-rw-r--r-- | typing_extensions/src/test_typing_extensions.py | 8 | ||||
-rw-r--r-- | typing_extensions/src/typing_extensions.py | 26 |
4 files changed, 30 insertions, 15 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a89af4..f0e6d67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,11 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11-dev"] + # We try to test on the earliest available bugfix release of each + # Python version, because typing sometimes changed between bugfix releases. + # For available versions, see: + # https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json + python-version: ["3.6", "3.6.7", "3.7", "3.7.1", "3.8", "3.8.0", "3.9", "3.9.0", "3.10", "3.10.0", "3.11-dev"] runs-on: ubuntu-latest diff --git a/typing_extensions/CHANGELOG b/typing_extensions/CHANGELOG index 831f6d8..d27af29 100644 --- a/typing_extensions/CHANGELOG +++ b/typing_extensions/CHANGELOG @@ -1,3 +1,8 @@ +# Release 4.1.1 (February 13, 2022) + +- Fix importing `typing_extensions` on Python 3.7.0 and 3.7.1. Original + patch by Nikita Sobolev (@sobolevn). + # Release 4.1.0 (February 12, 2022) - Runtime support for PEP 646, adding `typing_extensions.TypeVarTuple` diff --git a/typing_extensions/src/test_typing_extensions.py b/typing_extensions/src/test_typing_extensions.py index 62a9fd7..a66a2f2 100644 --- a/typing_extensions/src/test_typing_extensions.py +++ b/typing_extensions/src/test_typing_extensions.py @@ -131,7 +131,13 @@ class NoReturnTests(BottomTypeTestsMixin, BaseTestCase): def some_str(arg: 'NoReturn') -> 'typing.NoReturn': ... expected = {'arg': NoReturn, 'return': NoReturn} - for target in [some, some_str]: + targets = [some] + + # On 3.7.0 and 3.7.1, https://github.com/python/cpython/pull/10772 + # wasn't applied yet and NoReturn fails _type_check. + if not ((3, 7, 0) <= sys.version_info < (3, 7, 2)): + targets.append(some_str) + for target in targets: with self.subTest(target=target): self.assertEqual(gth(target), expected) diff --git a/typing_extensions/src/typing_extensions.py b/typing_extensions/src/typing_extensions.py index 144bca7..194731c 100644 --- a/typing_extensions/src/typing_extensions.py +++ b/typing_extensions/src/typing_extensions.py @@ -140,7 +140,7 @@ def _collect_type_vars(types, typevar_types=None): if ( isinstance(t, typevar_types) and t not in tvars and - not isinstance(t, _UnpackAlias) + not _is_unpack(t) ): tvars.append(t) if _should_collect_from_parameters(t): @@ -148,18 +148,6 @@ def _collect_type_vars(types, typevar_types=None): return tuple(tvars) -# We have to do some monkey patching to deal with the dual nature of -# Unpack/TypeVarTuple: -# - We want Unpack to be a kind of TypeVar so it gets accepted in -# Generic[Unpack[Ts]] -# - We want it to *not* be treated as a TypeVar for the purposes of -# counting generic parameters, so that when we subscript a generic, -# the runtime doesn't try to substitute the Unpack with the subscripted type. -if not hasattr(typing, "TypeVarTuple"): - typing._collect_type_vars = _collect_type_vars - typing._check_generic = _check_generic - - # 3.6.2+ if hasattr(typing, 'NoReturn'): NoReturn = typing.NoReturn @@ -2906,3 +2894,15 @@ else: } return cls_or_fn return decorator + + +# We have to do some monkey patching to deal with the dual nature of +# Unpack/TypeVarTuple: +# - We want Unpack to be a kind of TypeVar so it gets accepted in +# Generic[Unpack[Ts]] +# - We want it to *not* be treated as a TypeVar for the purposes of +# counting generic parameters, so that when we subscript a generic, +# the runtime doesn't try to substitute the Unpack with the subscripted type. +if not hasattr(typing, "TypeVarTuple"): + typing._collect_type_vars = _collect_type_vars + typing._check_generic = _check_generic |