[New-bugs-announce] [issue36178] type.__init__ called instead of cls.__init__ when inheriting from type.

Hameer Abbasi report at bugs.python.org
Mon Mar 4 03:44:53 EST 2019


New submission from Hameer Abbasi <einstein.edison at gmail.com>:

I may be completely misunderstanding here, but: here's a reproducible example:

class MyMeta(type):
    def __new__(cls, *args, **kwargs):
        print('__new__', *args, **kwargs)
        super().__new__(cls, *args, **kwargs)
    
    def __init__(self, a):
        print('__init__', *args, **kwargs)
        super().__init__(*args, **kwargs)

class A(metaclass=MyMeta):
    pass

MyMeta('A', (), {'__module__': '__main__', '__qualname__': 'A'})


Output:

__new__ A () {'__module__': '__main__', '__qualname__': 'A'}
__new__ A () {'__module__': '__main__', '__qualname__': 'A'}

Is this by design?

----------
components: Interpreter Core
messages: 337079
nosy: Hameer Abbasi
priority: normal
severity: normal
status: open
title: type.__init__ called instead of cls.__init__ when inheriting from type.
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36178>
_______________________________________


More information about the New-bugs-announce mailing list