Given the following behaviour:
def a():
pass
type(a)
>> function
If type of a
is function
, what is type
of function
?
type(function)
>> NameError: name 'function' is not defined
And why does type
of type
from a
is type
?
type(type(a))
>> type
Lastly: if a
is an object
, why it cannot be inherited?
isinstance(a, object)
>> True
class x(a):
pass
TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str
The type of any function is <type 'function'>
. The type of the type of function is <type 'type'>
, like you got with type(type(a))
. The reason type(function)
doesn't work is because type(function)
is trying to get the type of an undeclared variable called function
, not the type of an actual function (i.e. function
is not a keyword).
You are getting the metaclass error during your class definition because a
is of type function
and you can't subclass functions in Python.
Plenty of good info in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With