Message350235
Here's a case where `inspect.getsource` returns the wrong class definition when a file contains multiple class definitions with the same name. This pattern is valid runtime behavior when the class definitions are inside different scopes (e.g. a factory pattern where classes are defined and returned inside a function).
```
import inspect
def foo0():
class Foo:
x = 4
return Foo
def foo1():
class Foo:
x = 5
return Foo
print(inspect.getsource(foo1()))
print(foo1().x)
print(foo0().x)
```
Running this file produces
```
❯ python inspect-getsource-issue.py
class Foo:
x = 4
5
4
``` |
|
Date |
User |
Action |
Args |
2019-08-22 22:46:07 | lennyt | set | recipients:
+ lennyt |
2019-08-22 22:46:07 | lennyt | set | messageid: <1566513967.26.0.232695535045.issue37922@roundup.psfhosted.org> |
2019-08-22 22:46:07 | lennyt | link | issue37922 messages |
2019-08-22 22:46:07 | lennyt | create | |
|