Skip to content

Commit 2d7d89b

Browse files
committed
Merge branch 'main' into ci-use-codecov
# Conflicts: # .github/workflows/ci.yml
2 parents 7f04d25 + a240875 commit 2d7d89b

File tree

4 files changed

+95
-17
lines changed

4 files changed

+95
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ jobs:
6767
allow-prereleases: true
6868

6969
- name: Install coverage
70-
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
7170
run: |
7271
# Be wary that this does not install typing_extensions in the future.
7372
# 'toml' extra is needed to read settings from pyproject.toml on Python <3.11
7473
pip install 'coverage[toml]'
7574
7675
- name: Test typing_extensions with coverage
77-
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
7876
run: |
7977
# Be wary of running `pip install` here, since it becomes easy for us to
8078
# accidentally pick up typing_extensions as installed by a dependency
@@ -84,14 +82,6 @@ jobs:
8482
python -m coverage run -m unittest test_typing_extensions.py
8583
# Create xml file for Codecov
8684
coverage xml --rcfile=../pyproject.toml --fail-under=0
87-
- name: Test typing_extensions no coverage on pypy
88-
if: ${{ startsWith(matrix.python-version, 'pypy') }}
89-
run: |
90-
# Be wary of running `pip install` here, since it becomes easy for us to
91-
# accidentally pick up typing_extensions as installed by a dependency
92-
cd src
93-
python --version # just to make sure we're running the right one
94-
python -m unittest test_typing_extensions.py
9585
9686
- name: Test CPython typing test suite
9787
# Test suite fails on PyPy even without typing_extensions
@@ -104,11 +94,7 @@ jobs:
10494
10595
- name: Upload coverage reports to Codecov
10696
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
107-
if: >-
108-
${{
109-
!startsWith(matrix.python-version, 'pypy')
110-
&& (github.event_name == 'push' || github.event_name == 'pull_request')
111-
}}
97+
if: ${{ (github.event_name == 'push' || github.event_name == 'pull_request') }}
11298
with:
11399
token: ${{ secrets.CODECOV_ORG_TOKEN }}
114100
flags: ${{ matrix.python-version }}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Unreleased
22

3+
- Fix incorrect behaviour on Python 3.9 and Python 3.10 that meant that
4+
calling `isinstance` with `typing_extensions.Concatenate[...]` or
5+
`typing_extensions.Unpack[...]` as the first argument could have a different
6+
result in some situations depending on whether or not a profiling function had been
7+
set using `sys.setprofile`. This affected both CPython and PyPy implementations.
8+
Patch by Brian Schubert.
39
- Fix `__init_subclass__()` behavior in the presence of multiple inheritance involving
410
an `@deprecated`-decorated base class. Backport of CPython PR
511
[#138210](https://github.com/python/cpython/pull/138210) by Brian Schubert.

src/test_typing_extensions.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6230,6 +6230,47 @@ def test_is_param_expr(self):
62306230
self.assertTrue(typing._is_param_expr(concat))
62316231
self.assertTrue(typing._is_param_expr(typing_concat))
62326232

6233+
def test_isinstance_results_unaffected_by_presence_of_tracing_function(self):
6234+
# See https://github.com/python/typing_extensions/issues/661
6235+
6236+
code = textwrap.dedent(
6237+
"""\
6238+
import sys, typing
6239+
6240+
def trace_call(*args):
6241+
return trace_call
6242+
6243+
def run():
6244+
sys.modules.pop("typing_extensions", None)
6245+
from typing_extensions import Concatenate
6246+
return isinstance(Concatenate[...], typing._GenericAlias)
6247+
isinstance_result_1 = run()
6248+
sys.setprofile(trace_call)
6249+
isinstance_result_2 = run()
6250+
sys.stdout.write(f"{isinstance_result_1} {isinstance_result_2}")
6251+
"""
6252+
)
6253+
6254+
# Run this in an isolated process or it pollutes the environment
6255+
# and makes other tests fail:
6256+
try:
6257+
proc = subprocess.run(
6258+
[sys.executable, "-c", code], check=True, capture_output=True, text=True,
6259+
)
6260+
except subprocess.CalledProcessError as exc:
6261+
print("stdout", exc.stdout, sep="\n")
6262+
print("stderr", exc.stderr, sep="\n")
6263+
raise
6264+
6265+
# Sanity checks that assert the test is working as expected
6266+
self.assertIsInstance(proc.stdout, str)
6267+
result1, result2 = proc.stdout.split(" ")
6268+
self.assertIn(result1, {"True", "False"})
6269+
self.assertIn(result2, {"True", "False"})
6270+
6271+
# The actual test:
6272+
self.assertEqual(result1, result2)
6273+
62336274
class TypeGuardTests(BaseTestCase):
62346275
def test_basics(self):
62356276
TypeGuard[int] # OK
@@ -6652,6 +6693,46 @@ def test_type_var_inheritance(self):
66526693
self.assertFalse(isinstance(Unpack[Ts], TypeVar))
66536694
self.assertFalse(isinstance(Unpack[Ts], typing.TypeVar))
66546695

6696+
def test_isinstance_results_unaffected_by_presence_of_tracing_function(self):
6697+
# See https://github.com/python/typing_extensions/issues/661
6698+
6699+
code = textwrap.dedent(
6700+
"""\
6701+
import sys, typing
6702+
6703+
def trace_call(*args):
6704+
return trace_call
6705+
6706+
def run():
6707+
sys.modules.pop("typing_extensions", None)
6708+
from typing_extensions import TypeVarTuple, Unpack
6709+
return isinstance(Unpack[TypeVarTuple("Ts")], typing.TypeVar)
6710+
isinstance_result_1 = run()
6711+
sys.setprofile(trace_call)
6712+
isinstance_result_2 = run()
6713+
sys.stdout.write(f"{isinstance_result_1} {isinstance_result_2}")
6714+
"""
6715+
)
6716+
6717+
# Run this in an isolated process or it pollutes the environment
6718+
# and makes other tests fail:
6719+
try:
6720+
proc = subprocess.run(
6721+
[sys.executable, "-c", code], check=True, capture_output=True, text=True,
6722+
)
6723+
except subprocess.CalledProcessError as exc:
6724+
print("stdout", exc.stdout, sep="\n")
6725+
print("stderr", exc.stderr, sep="\n")
6726+
raise
6727+
6728+
# Sanity checks that assert the test is working as expected
6729+
self.assertIsInstance(proc.stdout, str)
6730+
result1, result2 = proc.stdout.split(" ")
6731+
self.assertIn(result1, {"True", "False"})
6732+
self.assertIn(result2, {"True", "False"})
6733+
6734+
# The actual test:
6735+
self.assertEqual(result1, result2)
66556736

66566737
class TypeVarTupleTests(BaseTestCase):
66576738

src/typing_extensions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,9 @@ class _ConcatenateGenericAlias(list):
19861986
__class__ = typing._GenericAlias
19871987

19881988
def __init__(self, origin, args):
1989-
super().__init__(args)
1989+
# Cannot use `super().__init__` here because of the `__class__` assignment
1990+
# in the class body (https://github.com/python/typing_extensions/issues/661)
1991+
list.__init__(self, args)
19901992
self.__origin__ = origin
19911993
self.__args__ = args
19921994

@@ -2545,7 +2547,10 @@ def __typing_is_unpacked_typevartuple__(self):
25452547
def __getitem__(self, args):
25462548
if self.__typing_is_unpacked_typevartuple__:
25472549
return args
2548-
return super().__getitem__(args)
2550+
# Cannot use `super().__getitem__` here because of the `__class__` assignment
2551+
# in the class body on Python <=3.11
2552+
# (https://github.com/python/typing_extensions/issues/661)
2553+
return typing._GenericAlias.__getitem__(self, args)
25492554

25502555
@_UnpackSpecialForm
25512556
def Unpack(self, parameters):

0 commit comments

Comments
 (0)