Author ncoghlan
Recipients Nate Soares, levkivskyi, ncoghlan
Date 2017-02-19.08:06:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1487491573.43.0.950624921704.issue29581@psf.upfronthosting.co.za>
In-reply-to
Content
This is going to be the case anytime an attempt is made to combine parent classes with incompatible constructor signatures. "type" is unusual in that it goes to great lengths to present an adaptive signature that aligns with whatever the class definition does.

The main relevant trick is to filter the extra arguments out from those passed to metaclasses such that only init_subclass sees them:

================
def ignore_extra_args(base):
    base_meta = type(base)
    class _FilteredMeta(base_meta):
        def __new__(*args, **kwds):
            return base_meta.__new__(*args)
        def __init__(*args, **kwds):
            return base_meta.__init__(*args)
    class _Filtered(base, metaclass=_FilteredMeta):
        pass
    return _Filtered

class InitX():
    def __init_subclass__(cls, x=None):
        print('x')

from abc import ABCMeta
class Abstract(metaclass=ABCMeta):
    pass

class AbstractWithInit(ignore_extra_args(Abstract), InitX, x=1):
    pass

AbstractWithInit()
================

If folks were to iterate on "ignore_extra_args" variants outside the standard library with 3.6, then it would be something we could sensibly standardise for 3.7.
History
Date User Action Args
2017-02-19 08:06:13ncoghlansetrecipients: + ncoghlan, levkivskyi, Nate Soares
2017-02-19 08:06:13ncoghlansetmessageid: <1487491573.43.0.950624921704.issue29581@psf.upfronthosting.co.za>
2017-02-19 08:06:13ncoghlanlinkissue29581 messages
2017-02-19 08:06:13ncoghlancreate