/Project
|-- main.py
|--/lib
| |--__init__.py
| |--foo.py
| |--Types.py
/Project/lib
has been added to the PYTHONPATH
variables.
Types.py:
class Custom(object):
def __init__(self):
a = 1
b = 2
foo.py:
from Types import Custom
def foo(o):
assert isinstance(o, Custom)
Finally, from main.py:
from lib.Types import Custom
from lib.foo import foo
a = Custom()
foo(a)
The problem now is, that a
is of type lib.foo.Custom
, while the isinstance call will check if it equals foo.Custom
, which obviously returns false.
How can I avoid this problem, without having to change anything in the library (lib)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…