New submission from Nate Soares:
I believe I've found a bug (or, at least, critical shortcoming) in the way that
python 3.6's __init_subclass__ interacts with abc.ABCMeta (and, presumably,
most other metaclasses in the standard library). In short, if a class
subclasses both an abstract class and a class-that-uses-__init_subclass__, and
the __init_subclass__ uses keyword arguments, then this will often lead to
TypeErrors (because the metaclass gets confused by the keyword arguments to
__new__ that were meant for __init_subclass__).
Here's an example of the failure. This code:
from abc import ABCMeta
class Initifier:
def __init_subclass__(cls, x=None, **kwargs):
super().__init_subclass__(**kwargs)
print('got x', x)
class Abstracted(metaclass=ABCMeta):
pass
class Thingy(Abstracted, Initifier, x=1):
pass
thingy = Thingy()
raises this TypeError when run:
Traceback (most recent call last):
File "<filename>", line 10, in <module>
class Thingy(Abstracted, Initifier, x=1):
TypeError: __new__() got an unexpected keyword argument 'x'
See
http://stackoverflow.com/questions/42281697/typeerror-when-combining-abcmeta-with-init-subclass-in-python-3-6
for further discussion.
----------
messages: 287966
nosy: Nate Soares
priority: normal
severity: normal
status: open
title: __init_subclass__ causes TypeError when used with standard library
metaclasses (such as ABCMeta)
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue29581>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com