Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,7 @@ def visit_class_def(self, o: ClassDef) -> None:
if isinstance(o.metaclass, (NameExpr, MemberExpr)):
meta = o.metaclass.accept(AliasPrinter(self))
base_types.append("metaclass=" + meta)
elif self.analyzed and o.info.is_protocol:
type_str = "Protocol"
if o.info.type_vars:
type_str += f'[{", ".join(o.info.type_vars)}]'
base_types.append(type_str)
self.add_typing_import("Protocol")
elif self.analyzed and o.info.is_abstract:
elif self.analyzed and o.info.is_abstract and not o.info.is_protocol:
base_types.append("metaclass=abc.ABCMeta")
self.import_tracker.add_import("abc")
self.import_tracker.require_name("abc")
Expand All @@ -933,7 +927,7 @@ def get_base_types(self, cdef: ClassDef) -> list[str]:
"""Get list of base classes for a class."""
base_types: list[str] = []
p = AliasPrinter(self)
for base in cdef.base_type_exprs:
for base in cdef.base_type_exprs + cdef.removed_base_type_exprs:
if isinstance(base, (NameExpr, MemberExpr)):
if self.get_fullname(base) != "builtins.object":
base_types.append(get_qualified_name(base))
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,17 @@ class D(Generic[T]): ...
[out]
class D(Generic[T]): ...

[case testGenericClass_semanal]
from typing import Generic, TypeVar
T = TypeVar('T')
class D(Generic[T]): ...
[out]
from typing import Generic, TypeVar

T = TypeVar('T')

class D(Generic[T]): ...

[case testObjectBaseClass]
class A(object): ...
[out]
Expand Down