python - Why is NotImplementedType not a type subclass? -
i noticed strange when inspecting built-in type notimplementedtype
.
>>> types import notimplementedtype >>> issubclass(notimplementedtype, type) false >>> type(notimplementedtype) <type 'type'>
how can these 2 things true? how can notimplementedtype
not subclass of type
yet derived type
?
classes not subclass of type
, including types.notimplementedtype
. type
metaclass of classes.
for example, custom classes , built-in types not subclasses of type
either:
>>> class foo: pass ... >>> issubclass(foo, type) false >>> issubclass(int, type) false
only other metaclasses subclasses of type
; abcmeta
metaclass:
>>> abc import abcmeta >>> issubclass(abcmeta, type) true
this analogous intances , classes; instances not subclasses of class; use isinstance()
:
>>> issubclass(foo(), foo) traceback (most recent call last): file "<stdin>", line 1, in <module> typeerror: issubclass() arg 1 must class >>> isinstance(foo(), foo) true >>> import types >>> isinstance(types.notimplementedtype, type) true
wiki
Comments
Post a Comment