Author Nate Soares
Recipients Nate Soares
Date 2017-02-16.18:54:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1487271247.7.0.447487107459.issue29581@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-02-16 18:54:07Nate Soaressetrecipients: + Nate Soares
2017-02-16 18:54:07Nate Soaressetmessageid: <1487271247.7.0.447487107459.issue29581@psf.upfronthosting.co.za>
2017-02-16 18:54:07Nate Soareslinkissue29581 messages
2017-02-16 18:54:07Nate Soarescreate