mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-39168: Remove the __new__ method of typing.Generic (GH-21327)
Automerge-Triggered-By: @gvanrossum
This commit is contained in:
parent
9c84417122
commit
7fed75597f
3 changed files with 1 additions and 12 deletions
|
@ -1417,8 +1417,6 @@ class GenericTests(BaseTestCase):
|
||||||
def test_generic_errors(self):
|
def test_generic_errors(self):
|
||||||
T = TypeVar('T')
|
T = TypeVar('T')
|
||||||
S = TypeVar('S')
|
S = TypeVar('S')
|
||||||
with self.assertRaises(TypeError):
|
|
||||||
Generic[T]()
|
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
Generic[T][T]
|
Generic[T][T]
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
|
|
|
@ -894,16 +894,6 @@ class Generic:
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
_is_protocol = False
|
_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
|
@_tp_cache
|
||||||
def __class_getitem__(cls, params):
|
def __class_getitem__(cls, params):
|
||||||
if not isinstance(params, tuple):
|
if not isinstance(params, tuple):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Remove the ``__new__`` method of :class:`typing.Generic`.
|
Loading…
Add table
Add a link
Reference in a new issue