Skip to content

Commit

Permalink
Fix Python 3.7.1 and run more versions in CI (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Feb 14, 2022
1 parent 16cf672 commit 83ed5bf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions typing_extensions/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
8 changes: 7 additions & 1 deletion typing_extensions/src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ def some(arg: NoReturn) -> NoReturn: ...
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)

Expand Down
26 changes: 13 additions & 13 deletions typing_extensions/src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,14 @@ 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):
tvars.extend([t for t in t.__parameters__ if t not in tvars])
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
Expand Down Expand Up @@ -2906,3 +2894,15 @@ def decorator(cls_or_fn):
}
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

0 comments on commit 83ed5bf

Please sign in to comment.