An object is an instance (or not)?
alex23
wuwei23 at gmail.com
Tue Jan 27 23:44:10 EST 2015
On 28/01/2015 10:35 AM, Mario Figueiredo wrote:
> I admit it was a contrived example. I couldn't think of a way to
> demonstrate that a class object does not participate in its own
> inheritance rules. Only instances of it can.
A class object isn't an instance of itself, it's an instance of the
Class (to be extact, 'type') class. Method dispatching will also
traverse the base classes when refering to the class object, too:
>>> class Master:
... @classmethod
... def func(cls):
... return cls
...
>>> class Sub(Master):
... pass
...
>>> type(Sub)
<class 'type'>
>>> Sub.func()
<class '__main__.Sub'>
More information about the Python-list
mailing list