Skip to content

Commit

Permalink
bpo-43827: Make arguments to abc.ABCMeta.__new__ pos-only (#25385)
Browse files Browse the repository at this point in the history
To avoid conflicts with `__init__subclass__`.
  • Loading branch information
vladhoi committed May 5, 2022
1 parent a95138b commit 42fee93
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ABCMeta(type):
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
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,19 @@ def __init_subclass__(cls, **kwargs):
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,
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ Albert Hofkamp
Chris Hogan
Tomas Hoger
Jonathan Hogg
Vladyslav Hoi
Kamilla Holanda
Steve Holden
Akintayo Holder
Expand Down
Original file line number Diff line number Diff line change
@@ -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__`.

0 comments on commit 42fee93

Please sign in to comment.