For instance, the class declaration:
class Something(Superclass):
an_attribute = 1
another_attribute = 'hello'
Is there any way that python can tell me that an_attribute and another_attribute were defined in this class declaration?
Another way of framing this question, I guess, is “can I filter dir results by the class in which they were declared?
The attributes of a class are kept in it’s special
__dict__field. The__dict__contains only the attributes defined for the current class (as well as the special attributes). As others mentioned, it can be accessed either directly or via built-invars()function.I strongly recommend reading this article which explains how Python handles attributes in-depth.