Closed xianyuanjia closed 2 years ago
According to the cpython source codes:
https://github.com/python/cpython/blob/3.9/Lib/inspect.py#L351
When using inspect with class instance:inspect.getmembers(Foo(), callable)
It will call getattr(foo_instance, key)
on all keys from dir(foo_instance)
, therefore the bar
property getter will be called.
When using inspect with class type: inspect.getmembers(Foo, callable)
It will call getattr(Foo, key)
on all keys from dir(Foo)
, the bar
property getter will not be called.
Another approach we can consider is to use dir
instead of inspect.getmembers
.
This prevents inspect.getmembers from calling the properties of given test class.
e.g.
This change is