diff --git a/mypy/test/teststubgen.py b/mypy/test/teststubgen.py index 84811a8b43ad..41f93b7db45e 100644 --- a/mypy/test/teststubgen.py +++ b/mypy/test/teststubgen.py @@ -946,16 +946,17 @@ class TestClass: @unittest.skipIf(sys.version_info < (3, 12), "Inline Generics not supported before Python3.12") def test_generic_class(self) -> None: - # mypy: enable-incomplete-feature=NewGenericSyntax - exec("class Test[A]: ...") - - class TestClass[A]: ... - - output: list[str] = [] - mod = ModuleType("module", "") - gen = InspectionStubGenerator(mod.__name__, known_modules=[mod.__name__], module=mod) - gen.generate_class_stub("C", TestClass, output) - assert_equal(output, ["class C[A]: ..."]) + # This test lives in the exec block to avoid syntax version on python versions < 3.12 + code = """ +class Test[A]: ... + +output: list[str] = [] +mod = ModuleType("module", "") +gen = InspectionStubGenerator(mod.__name__, known_modules=[mod.__name__], module=mod) +gen.generate_class_stub("C", Test, output) +assert_equal(output, ["class C[A]: ..."]) + """ + exec(code) @unittest.skipIf(sys.version_info < (3, 12), "Inline Generics not supported before Python3.12") def test_inline_generic_function(self) -> None: