You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling inspect.getmembers on a class that has a property (@Property), the property will be called by the getattr call in getmembers.
Example:
importinspectclassExample:
def__init__(self, var):
self._var=varprint('__init__')
deffoo(self, bar):
print(bar)
print('foo')
@propertydefvar(self):
print('Access property')
returnself._varif__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...>)]
I feel like I came to a dead end with this issue. As I am fairly new to CPython and have never contributed to this project before, I have no idea how to address this and to whom. Maybe this is just to irrelevant and not important, but even then we should probably close this issue or mark it as "indefinitely postponed" or something similar.
jnsdrtlf commented on Mar 29, 2020
jnsdrtlfmannequin
MannequinAuthor
More actions
I'm still thinking about this bug/issue/undefined behaviour. Today I wanted to test its behaviour with async:
RuntimeWarning: coroutine 'Foo.spam' was never awaited
members = inspect.getmembers(instance)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Sure, async properties might not be particularly beautiful or best-practice, but I frequently stumble upon code where getmembers would fail – just like this example. However, I am still clueless about what to do.
Activity
jnsdrtlf commentedon Oct 1, 2019
When calling inspect.getmembers on a class that has a property (@Property), the property will be called by the getattr call in 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...>)]
s-sanjay commentedon Oct 1, 2019
the issue happens in 2.7 as well
hongweipeng commentedon Oct 3, 2019
The results of this example are different from mine(version 3.7.4).
jnsdrtlf commentedon Oct 3, 2019
I do not really see any difference. What do you mean?
hongweipeng commentedon Oct 4, 2019
I mean why member
__class__is expected to be<attribute '__class__'...>). I check PR16521,for class, it always gets<attribute '__class__'...>).jnsdrtlf commentedon Oct 4, 2019
Oh, yes I see what you mean. That's my fault, it seems like I copied the wrong line. Sorry.
But the important piece is the 'var' attribute. Sorry for the confusion.
csabella commentedon Jan 26, 2020
Here is a link to the discussion of this on ideas:
https://discuss.python.org/t/implement-inspect-getmembers-static/2550
jnsdrtlf commentedon Jan 27, 2020
Thank you for posting the link.
I feel like I came to a dead end with this issue. As I am fairly new to CPython and have never contributed to this project before, I have no idea how to address this and to whom. Maybe this is just to irrelevant and not important, but even then we should probably close this issue or mark it as "indefinitely postponed" or something similar.
jnsdrtlf commentedon Mar 29, 2020
I'm still thinking about this bug/issue/undefined behaviour. Today I wanted to test its behaviour with async:
This will result in a RuntimeWarning:
RuntimeWarning: coroutine 'Foo.spam' was never awaited
members = inspect.getmembers(instance)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Sure, async properties might not be particularly beautiful or best-practice, but I frequently stumble upon code where getmembers would fail – just like this example. However, I am still clueless about what to do.
interifter commentedon May 30, 2025
Looks like this is still around with at least 3.12. Not a popular bug :)