[New-bugs-announce] [issue38337] inspect: getmembers calls properties
Jonas Drotleff
report at bugs.python.org
Tue Oct 1 08:01:59 EDT 2019
New submission from Jonas Drotleff <jonas.drotleff at gmail.com>:
When calling inspect.getmembers on a class that has a property (@property), the property will be called by the getattr call in getmembers.
Example:
import inspect
class Example:
def __init__(self, var):
self._var = var
print('__init__')
def foo(self, bar):
print(bar)
print('foo')
@property
def var(self):
print('Access property')
return self._var
if __name__ == '__main__':
ex = Example('Hello')
print('--- getmembers from instance ---')
print(inspect.getmembers(ex))
print('--- getmembers from class ---')
print(inspect.getmembers(Example))
Result:
__init__
--- getmembers from instance ---
Access property
[('__class__', <attribute '__class__' of 'object' objects>), ..., ('var', 'Hello')]
--- getmembers from class ---
[('__class__', <attribute '__class__' of 'object' objects>), ..., ('var', <property object at 0x...>)]
Expected:
__init__
--- getmembers from instance ---
[('__class__', <attribute '__class__' of 'object' objects>), ..., ('var', <property object at 0x...>)]
--- getmembers from class ---
[('__class__', <attribute '__class__' of 'object' objects>), ..., ('var', <property object at 0x...>)]
----------
components: Library (Lib)
messages: 353688
nosy: jnsdrtlf
priority: normal
severity: normal
status: open
title: inspect: getmembers calls properties
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38337>
_______________________________________
More information about the New-bugs-announce
mailing list