8000 Add test cases · python/cpython@394d128 · GitHub
[go: up one dir, main page]

Skip to content

Commit 394d128

Browse files
committed
Add test cases
1 parent 2e913ca commit 394d128

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Lib/test/test_type_params.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,42 @@ class Foo[T: Undefined, U: (Undefined,)]:
305305
self.assertEqual(type_params[1].__constraints__, ("defined",))
306306

307307

308+
class TypeParamsClassScopeTest(unittest.TestCase):
309+
def test_alias(self):
310+
class X:
311+
T = int
312+
type U = T
313+
self.assertIs(X.U.__value__, int)
314+
315+
code = textwrap.dedent("""\
316+
glb = "global"
317+
class X:
318+
cls = "class"
319+
type U = (glb, cls)
320+
321+
assert X.U.__value__ == ("global", "class"), X.U.__value__
322+
""")
323+
exec(code, {})
324+
325+
def test_bound(self):
326+
class X:
327+
T = int
328+
def foo[U: T](self): ...
329+
self.assertIs(X.foo.__type_params__[0].__bound__, int)
330+
331+
code = textwrap.dedent("""\
332+
glb = "global"
333+
class X:
334+
cls = "class"
335+
def foo[T: glb, U: cls](self): ...
336+
337+
T, U = X.foo.__type_params__
338+
assert T.__bound__ == "global"
339+
assert U.__bound__ == "class"
340+
""")
341+
exec(code, {})
342+
343+
308344
class TypeParamsTraditionalTypeVars(unittest.TestCase):
309345
def test_traditional_01(self):
310346
code = textwrap.dedent("""\

Python/symtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,8 +1958,8 @@ symtable_visit_typeparam(struct symtable *st, typeparam_ty tp)
19581958
VISIT(st, expr, tp->v.TypeVar.bound);
19591959
if (!symtable_exit_block(st))
19601960
VISIT_QUIT(st, 0);
1961+
}
19611962
break;
1962-
}
19631963
case TypeVarTuple_kind:
19641964
if (!symtable_add_def(st, tp->v.TypeVarTuple.name, DEF_TYPE_PARAM | DEF_LOCAL, LOCATION(tp)))
19651965
VISIT_QUIT(st, 0);

0 commit comments

Comments
 (0)
0