[issue40098] dir() does not return the list of valid attributes for the object

Serhiy Storchaka report at bugs.python.org
Tue Mar 31 17:05:18 EDT 2020


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

If using __class__ and __dict__ attribuites is a feature, it does not work for __getattr__(). I think it is confusing if __dir__() and __getattr__() are not consistent. I'll try to deal with unittes.mock and then will look how this will work with other classes that override __class__ or __dict__. Also we need to check all classes with custom __getattr__ for the matter of custom __dir__.

I think that it might be better if dir() for instance excluded names which are not accessed as via instance, e.g. non-descriptor class attributes and class methods. But it may be not easy to do.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40098>
_______________________________________


More information about the Python-bugs-list mailing list