From b82c9cd4f4307951de2148e84aca898d5a8c1792 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Fri, 17 May 2024 13:56:37 +0100 Subject: [PATCH] Add test cases --- test-data/unit/check-python312.test | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test-data/unit/check-python312.test b/test-data/unit/check-python312.test index eb3b5c6cc3ec..97a6efbd64dc 100644 --- a/test-data/unit/check-python312.test +++ b/test-data/unit/check-python312.test @@ -1104,3 +1104,36 @@ def g[T](x: T) -> T: def nested2[S](y: S) -> S: return y return x + +[case testPEP695NestedScopingSpecialCases] +# mypy: enable-incomplete-feature=NewGenericSyntax +# This is adapted from PEP 695 +S = 0 + +def outer1[S]() -> None: + S = 1 + T = 1 + + def outer2[T]() -> None: + def inner1() -> None: + nonlocal S + nonlocal T # E: nonlocal binding not allowed for type parameter "T" + + def inner2() -> None: + global S + +[case testPEP695ScopingWithBaseClasses] +# mypy: enable-incomplete-feature=NewGenericSyntax +# This is adapted from PEP 695 +class Outer: + class Private: + pass + + # If the type parameter scope was like a traditional scope, + # the base class 'Private' would not be accessible here. + class Inner[T](Private, list[T]): + pass + + # Likewise, 'Inner' would not be available in these type annotations. + def method1[T](self, a: Inner[T]) -> Inner[T]: + return a