From b88917088f6047cdb7eed5ec3be2985fb33c82b7 Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Tue, 23 Jul 2024 11:12:11 -0400 Subject: [PATCH] simpler exec --- mypy/test/teststubgen.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/mypy/test/teststubgen.py b/mypy/test/teststubgen.py index 31f4e2d699a8..0e270eebfdf9 100644 --- a/mypy/test/teststubgen.py +++ b/mypy/test/teststubgen.py @@ -946,17 +946,15 @@ class TestClass: @unittest.skipIf(sys.version_info < (3, 12), "Inline Generics not supported before Python3.12") def test_generic_class(self) -> None: - # This test lives in the exec block to avoid syntax errors 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) + # This class declaration lives in exec to avoid syntax version on python versions < 3.12 + local: dict[str, Any] = {} + exec("class Test[A]: ...", globals(), local) + + output: list[str] = [] + mod = ModuleType("module", "") + gen = InspectionStubGenerator(mod.__name__, known_modules=[mod.__name__], module=mod) + gen.generate_class_stub("C", local['Test'], output) + assert_equal(output, ["class C[A]: ..."]) @unittest.skipIf(sys.version_info < (3, 12), "Inline Generics not supported before Python3.12") def test_inline_generic_function(self) -> None: