-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inspect: getmembers calls properties #82518
Comments
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__ Expected: __init__ |
the issue happens in 2.7 as well |
The results of this example are different from mine(version 3.7.4).
|
I do not really see any difference. What do you mean? |
I mean why member |
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. |
Here is a link to the discussion of this on ideas: |
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. |
I'm still thinking about this bug/issue/undefined behaviour. Today I wanted to test its behaviour with async: import inspect
class Foo:
def __init__(self, bar):
self._bar = bar
if __name__ == '__main__':
instance = Foo('eggs')
members = inspect.getmembers(instance) This will result in a RuntimeWarning: RuntimeWarning: coroutine 'Foo.spam' was never awaited 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. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: