diff options
author | Vlad Hoi <hoivladyslav@yahoo.com> | 2022-05-05 13:40:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-05 13:40:01 (GMT) |
commit | 42fee931d055a3ef8ed31abe44603b9b2856e04d (patch) | |
tree | 91ea3744ac0ad4c67322f356b0d5b8d48bc70334 | |
parent | a95138b2c5a3ba3d9a1a635566e22e5843b6a45c (diff) | |
download | cpython-42fee931d055a3ef8ed31abe44603b9b2856e04d.zip cpython-42fee931d055a3ef8ed31abe44603b9b2856e04d.tar.gz cpython-42fee931d055a3ef8ed31abe44603b9b2856e04d.tar.bz2 |
bpo-43827: Make arguments to abc.ABCMeta.__new__ pos-only (#25385)
To avoid conflicts with `__init__subclass__`.
-rw-r--r-- | Lib/abc.py | 2 | ||||
-rw-r--r-- | Lib/test/test_abc.py | 13 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2021-04-16-17-32-44.bpo-43827.uJaXdP.rst | 1 |
4 files changed, 16 insertions, 1 deletions
@@ -102,7 +102,7 @@ else: implementations defined by the registering ABC be callable (not even via super()). """ - def __new__(mcls, name, bases, namespace, **kwargs): + def __new__(mcls, name, bases, namespace, /, **kwargs): cls = super().__new__(mcls, name, bases, namespace, **kwargs) _abc_init(cls) return cls diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py index c1d750d..1e7a035 100644 --- a/Lib/test/test_abc.py +++ b/Lib/test/test_abc.py @@ -668,6 +668,19 @@ def test_factory(abc_ABCMeta, abc_get_cache_token): class Receiver(ReceivesClassKwargs, abc_ABC, x=1, y=2, z=3): pass self.assertEqual(saved_kwargs, dict(x=1, y=2, z=3)) + + def test_positional_only_and_kwonlyargs_with_init_subclass(self): + saved_kwargs = {} + + class A: + def __init_subclass__(cls, **kwargs): + super().__init_subclass__() + saved_kwargs.update(kwargs) + + class B(A, metaclass=abc_ABCMeta, name="test"): + pass + self.assertEqual(saved_kwargs, dict(name="test")) + return TestLegacyAPI, TestABC, TestABCWithInitSubclass TestLegacyAPI_Py, TestABC_Py, TestABCWithInitSubclass_Py = test_factory(abc.ABCMeta, @@ -753,6 +753,7 @@ Albert Hofkamp Chris Hogan Tomas Hoger Jonathan Hogg +Vladyslav Hoi Kamilla Holanda Steve Holden Akintayo Holder diff --git a/Misc/NEWS.d/next/Library/2021-04-16-17-32-44.bpo-43827.uJaXdP.rst b/Misc/NEWS.d/next/Library/2021-04-16-17-32-44.bpo-43827.uJaXdP.rst new file mode 100644 index 0000000..6e4f82f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-04-16-17-32-44.bpo-43827.uJaXdP.rst @@ -0,0 +1 @@ +All positional-or-keyword parameters to ``ABCMeta.__new__`` are now positional-only to avoid conflicts with keyword arguments to be passed to :meth:`__init_subclass__`. |