Before modifying the c.py file, why do two different results appear? The results show that the two classes are different. What happened to issubclass? Here I use globals() to modify the global variables. Is there a better way?
"""
├─myapp
| ├─mypackge
| ├─init.py
| ├─a.py
│ ├─b.py
| ├─c.py
"""
#a.py
class A:
pass
#b.py
from mypackge.a import A
class B(A):
pass
#c.py
from a import A as A1
from mypackge.a import A as A2
from b import B
print(A1, A2) # output: <class 'a.A'> <class 'mypackage.a.A'>
print(issubclass(B, A1)) # output: False
print(issubclass(B, A2)) # output: True
# Next, I try to modify the c.py file using globals()
from a import A as A1
from mypackage.a import A as A2
from b import B
from pprint import pprint
pprint(globals())
print('-' * 50)
globals()['A1'] = A2
pprint(globals())
print(issubclass(B, A1))
print(issubclass(B, A2))
# ouput:
"""
{'A1': <class 'a.A'>,
'A2': <class 'mypackage.a.A'>,
'B': <class 'b.B'>,
...
--------------------------------------------------
{'A1': <class 'mypackage.a.A'>,
'A2': <class 'mypackage.a.A'>,
'B': <class 'b.B'>,
...
True
True
"""