Skip to content

Commit

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

0 comments on commit 74027b7

Please sign in to comment.