Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

5. dir(module) does not contain module type attributes (in contrary to dir() 
for regular object).

>>> import keyword
>>> dir(keyword)
['__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', 
'__name__', '__package__', '__spec__', 'iskeyword', 'kwlist']
>>> sorted(object.__dir__(keyword))
['__all__', '__builtins__', '__cached__', '__class__', '__delattr__', 
'__dict__', '__dir__', '__doc__', '__eq__', '__file__', '__format__', '__ge__', 
'__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', 
'__le__', '__loader__', '__lt__', '__name__', '__ne__', '__new__', 
'__package__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__sizeof__', '__spec__', '__str__', '__subclasshook__', 'iskeyword', 'kwlist']

Seems dir() was initially designed for old-style objects and many changes in 
object model were passed its.

On one hand, it would look logical if dir() returned the list of all names that 
can be used as attributes. But my concerns are that it may add a "noise", names 
which can be legally used as attribute names, but which are rarely accessed as 
instance attribute instead of type attributes. This applies to 1 (metaclasses) 
and 5 (module type).

If left out 1 and 5 and implement all other options (and I remind that it 
simplifies the code), it will only break one test for unittest.mock. I'm 
exploring what's going on there.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40098>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to