Skip to content

Commit

Permalink
simpler exec
Browse files Browse the repository at this point in the history
  • Loading branch information
InvincibleRMC committed Jul 23, 2024
1 parent fb0e698 commit b889170
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions mypy/test/teststubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b889170

Please sign in to comment.