You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[case testSuperclassInImportCycle]
import a
import d
a.A().f(d.D())
[file a.py]
if 0:
import d
class B: pass
class C(B): pass
class A:
def f(self, x: B) -> None: pass
[file d.py]
import a
class D(a.C): pass
with the error Argument 1 to "f" of "A" has incompatible type "D"; expected "B".
This test case is a reduction from mypy itself (a = mypy.types, A = Type, B = TypeVisitor, C = TypeTranslator, D is any type transformation defined in another module d). The test does not fail if the mypy-import of module d in module a is removed. Nor does it fail if the order of the imports in the main module is reversed. I found this counterintuitive at first, but upon reflection I guess it's because the order of traversing imports changes from main(a(d())) to main(d(a())), so whichever module is imported first is actually processed second.
I got as far as determining that something causes the MRO of D to be computed before the base classes of C are known. So the MRO of D ends up being computed as [D, C, object], which does not contain B. Seems that we could know when processing D that it has a base class in a module a that we are still in the middle of processing, and update the MRO of D when we finish processing a.
(#481 is the general ticket for issues involving import cycles.)
The text was updated successfully, but these errors were encountered:
rwbarton
added a commit
to rwbarton/mypy
that referenced
this issue
Apr 17, 2016
The following test case fails:
with the error
Argument 1 to "f" of "A" has incompatible type "D"; expected "B"
.This test case is a reduction from mypy itself (
a = mypy.types
,A = Type
,B = TypeVisitor
,C = TypeTranslator
,D
is any type transformation defined in another moduled
). The test does not fail if the mypy-import of moduled
in modulea
is removed. Nor does it fail if the order of the imports in the main module is reversed. I found this counterintuitive at first, but upon reflection I guess it's because the order of traversing imports changes frommain(a(d()))
tomain(d(a()))
, so whichever module is imported first is actually processed second.I got as far as determining that something causes the MRO of
D
to be computed before the base classes ofC
are known. So the MRO ofD
ends up being computed as[D, C, object]
, which does not containB
. Seems that we could know when processingD
that it has a base class in a modulea
that we are still in the middle of processing, and update the MRO ofD
when we finish processinga
.(#481 is the general ticket for issues involving import cycles.)
The text was updated successfully, but these errors were encountered: