[New-bugs-announce] [issue29117] dir(<bound method>) should include dunder attributes of the unbound method
Antony Lee
report at bugs.python.org
Fri Dec 30 16:51:10 EST 2016
New submission from Antony Lee:
```
Python 3.5.2 (default, Nov 7 2016, 11:31:36)
[GCC 6.2.1 20160830] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class C:
... def f(self): pass
...
>>> C.f.attr = 42
>>> print(dir(C.f))
['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'attr']
>>> print(dir(C().f))
['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__func__', '__ge__', '__get__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'attr']
>>>
```
Note that `dir(C().f)` does include the custom `attr` attribute, but is missing some of the dunder attributes (e.g. `__annotations__`), which are actually accessible directly from the boun method.
----------
components: Interpreter Core
messages: 284347
nosy: Antony.Lee
priority: normal
severity: normal
status: open
title: dir(<bound method>) should include dunder attributes of the unbound method
versions: Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29117>
_______________________________________
More information about the New-bugs-announce
mailing list