Skip to content
Snippets Groups Projects
Unverified Commit 42fee931 authored by Vlad Hoi's avatar Vlad Hoi Committed by GitHub
Browse files

bpo-43827: Make arguments to abc.ABCMeta.__new__ pos-only (#25385)

To avoid conflicts with `__init__subclass__`.
parent a95138b2
No related branches found
No related tags found
No related merge requests found
...@@ -102,7 +102,7 @@ class ABCMeta(type): ...@@ -102,7 +102,7 @@ class ABCMeta(type):
implementations defined by the registering ABC be callable (not implementations defined by the registering ABC be callable (not
even via super()). 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) cls = super().__new__(mcls, name, bases, namespace, **kwargs)
_abc_init(cls) _abc_init(cls)
return cls return cls
......
...@@ -668,6 +668,19 @@ def __init_subclass__(cls, **kwargs): ...@@ -668,6 +668,19 @@ def __init_subclass__(cls, **kwargs):
class Receiver(ReceivesClassKwargs, abc_ABC, x=1, y=2, z=3): class Receiver(ReceivesClassKwargs, abc_ABC, x=1, y=2, z=3):
pass pass
self.assertEqual(saved_kwargs, dict(x=1, y=2, z=3)) 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 return TestLegacyAPI, TestABC, TestABCWithInitSubclass
TestLegacyAPI_Py, TestABC_Py, TestABCWithInitSubclass_Py = test_factory(abc.ABCMeta, TestLegacyAPI_Py, TestABC_Py, TestABCWithInitSubclass_Py = test_factory(abc.ABCMeta,
......
...@@ -753,6 +753,7 @@ Albert Hofkamp ...@@ -753,6 +753,7 @@ Albert Hofkamp
Chris Hogan Chris Hogan
Tomas Hoger Tomas Hoger
Jonathan Hogg Jonathan Hogg
Vladyslav Hoi
Kamilla Holanda Kamilla Holanda
Steve Holden Steve Holden
Akintayo Holder Akintayo Holder
......
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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment