Skip to content

bpo-39168: Remove the __new__ method of typing.Generic #21327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
2 changes: 0 additions & 2 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1417,8 +1417,6 @@ def test_basics(self):
def test_generic_errors(self):
T = TypeVar('T')
S = TypeVar('S')
with self.assertRaises(TypeError):
Generic[T]()
with self.assertRaises(TypeError):
Generic[T][T]
with self.assertRaises(TypeError):
Expand Down
10 changes: 0 additions & 10 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,16 +894,6 @@ def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
__slots__ = ()
_is_protocol = False

def __new__(cls, *args, **kwds):
if cls in (Generic, Protocol):
raise TypeError(f"Type {cls.__name__} cannot be instantiated; "
"it can be used only as a base class")
if super().__new__ is object.__new__ and cls.__init__ is not object.__init__:
obj = super().__new__(cls)
else:
obj = super().__new__(cls, *args, **kwds)
return obj

@_tp_cache
def __class_getitem__(cls, params):
if not isinstance(params, tuple):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove the ``__new__`` method of :class:`typing.Generic`.