I have Python class looking somewhat like this:
class some_class:
def __getattr__(self, name):
# Do something with "name" (by passing it to a server)
Sometimes, I am working with ptpython
(an interactive Python shell) for debugging. ptpython
inspects instances of the class and tries to access the __objclass__
attribute, which does not exist. In __getattr__
, I could simply check if name != "__objclass__"
before working with name
, but I'd like to know whether there is a better way by either correctly implementing or somehow stubbing __objclass__
.
The Python documentation does not say very much about it, or at least I do not understand what I have to do:
The attribute
__objclass__
is interpreted by theinspect
module as specifying the class where this object was defined (setting this appropriately can assist in runtime introspection of dynamic class attributes). For callables, it may indicate that an instance of the given type (or a subclass) is expected or required as the first positional argument (for example, CPython sets this attribute for unbound methods that are implemented in C).