[issue38337] inspect: getmembers calls properties

Jonas Drotleff report at bugs.python.org
Sun Mar 29 15:22:40 EDT 2020


Jonas Drotleff <jonas.drotleff at gmail.com> added the comment:

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

    @property
    async def spam(self):
        print('Called spam')
        return self._bar


if __name__ == '__main__':
    instance = Foo('eggs')
    members = inspect.getmembers(instance)

##

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.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38337>
_______________________________________


More information about the Python-bugs-list mailing list