Skip to content

Commit

Permalink
Add rest of test case
Browse files Browse the repository at this point in the history
  • Loading branch information
InvincibleRMC committed Jul 23, 2024
1 parent d0b6f2e commit b4e40b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mypy/stubgenc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import inspect
import keyword
import os.path
from contextlib import suppress
from types import FunctionType, ModuleType
from typing import Any, Callable, Mapping

Expand Down Expand Up @@ -497,6 +498,8 @@ def is_skipped_attribute(self, attr: str) -> bool:
"__firstlineno__",
"__static_attributes__",
"__annotate__",
"__orig_bases__",
"__parameters__",
)
or attr in self.IGNORED_DUNDERS
or is_pybind_skipped_attribute(attr) # For pickling
Expand Down Expand Up @@ -875,6 +878,10 @@ def generate_class_stub(self, class_name: str, cls: type, output: list[str]) ->
self.dedent()

bases = self.get_base_types(cls)
if inline_generic != "":
# Removes typing.Generic form bases if it exists for python3.12 inline generics
with suppress(ValueError):
bases.remove("typing.Generic")
if bases:
bases_str = "(%s)" % ", ".join(bases)
else:
Expand Down
8 changes: 8 additions & 0 deletions mypy/test/teststubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,14 @@ class TestClass:
def test_generic_class(self) -> None:
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]: ..."])

@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 b4e40b5

Please sign in to comment.