Skip to content Skip to sidebar Skip to footer

Python 3.9 Metaclass Property Vs Classmethod Property

Consider the following code from abc import ABC, ABCMeta class MyMetaClass(ABCMeta): @property def metaclass_property(cls): return 'result' # def __dir__(cls

Solution 1:

I think this has nothing to do with properties, metaclasses or abc.

A simple example:

>>> int.__mro__
(<class'int'>, <class'object'>)
>>> isinstance(int, type)
True>>> '__mro__'indir(int)
False>>> '__mro__'indir(type)
True

In this example, object is the base class of int, while type is the metaclass of int.

The official documentation of the dir function explicitly says that it

attempts to produce the most relevant, rather than complete, information

and

If the object is a type or class object, the list contains the names of its attributes, and recursively of the attributes of its bases.

and

metaclass attributes are not in the result list when the argument is a class

Post a Comment for "Python 3.9 Metaclass Property Vs Classmethod Property"