Skip to content

Commit 6950f75

Browse files
committed
Add new test to test_typing.py to demonstrate fixed behaviour in gh-130870
1 parent 07815dd commit 6950f75

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Lib/test/test_typing.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10772,6 +10772,20 @@ def func_packed(arg1: int, arg2: str) -> bool:
1077210772
def test_hashable(self):
1077310773
self.assertEqual(hash(typing._UnionGenericAlias), hash(Union))
1077410774

10775+
class TestCallableAlias(BaseTestCase):
10776+
def test_callable_alias_preserves_subclass(self):
10777+
C = Callable[[str, ForwardRef("int")], int]
10778+
class A:
10779+
c: C
10780+
10781+
hints = get_type_hints(A)
10782+
10783+
# Ensure evaluated type retains the correct class
10784+
self.assertEqual(hints['c'].__class__, C.__class__)
10785+
10786+
# Instead of comparing raw ForwardRef, check if the resolution is correct
10787+
expected_args = tuple(int if isinstance(arg, ForwardRef) else arg for arg in C.__args__)
10788+
self.assertEqual(hints['c'].__args__, expected_args)
1077510789

1077610790
def load_tests(loader, tests, pattern):
1077710791
import doctest

0 commit comments

Comments
 (0)