I have a circular dependency caused by type-hinting analogous to this minimal example:
a.py:
from comparison import are_equal
class A:
def __eq__(self, other):
if not isinstance(other, A):
return NotImplemented
return are_equal(self, other)
comparison.py:
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from a import A
def are_equal(x: A, y: A):
...
While I would expect everything to work this way, I get the following error messages pointing to the last line of "a.py":
Argument of type "Self@A" is cannot be assigned to parameter "x" of type "A" in function "are_equal"
".A" is incompatible with "a.A"
Argument of type "A" is cannot be assigned to parameter "y" of type "A" in function "are_equal"
".A" is incompatible with "a.A"
Is there any way to fix this issue besides just opting out of type-checking by using # type: ignore
on that line?
Edit:
This does not seem to be a general issue but specific to my editor setup. I am using doom emacs and both files (a.py, comparison.py) are generated (tangled) from a single .org file. The error is shown when editing the source code block containing a.py in the special editing buffer (org-edit-src-code).