__init__ is not invoked

Oscar Benjamin oscar.j.benjamin at gmail.com
Thu Sep 26 10:35:55 EDT 2019


On Thu, 26 Sep 2019 at 13:39, Rhodri James <rhodri at kynesim.co.uk> wrote:
>
> On 26/09/2019 13:20, ast wrote:
> >
> >  >>> class ClassB(object):
> > ...     def __new__(cls, arg):
> > ...         print('__new__ ' + arg)
> > ...         return object
> > ...     def __init__(self, arg):
> > ...         print('__init__ ' + arg)
> > ...
> >
> >  >>> o = ClassB("Hello")
> > __new__ Hello
<snip>

> You have returned the class object, not
> an instance of anything,

Well object is an instance of object as well as of type:

>>> isinstance(object, object)
True
>>> isinstance(object, type)
True
>>> isinstance(type, object)
True
>>> isinstance(type, type)
True
>>> issubclass(object, type)
False
>>> issubclass(type, object)
True
>>> type.mro(type)
[<class 'type'>, <class 'object'>]
>>> type.mro(object)
[<class 'object'>]
>>> type(object)
<class 'type'>
>>> type(type)
<class 'type'>

--
Oscar



More information about the Python-list mailing list