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
{{ message }}
Repository navigation
mypyc assertion error when generating __ne__ from inherited __eq__ in package import cycle #21566
mypyc can fail with an internal AssertionError when it tries to generate __ne__ from an inherited __eq__.
This happens when the inherited method's declaration is available before its FuncIR body has been generated. One way to trigger this is with a package import cycle where __init__.py imports a child module before importing the subpackage that defines the base class.
To Reproduce
Add this test case to mypyc/test-data/run-multimodule.test:
[case testPackageCycleInheritedEq]
from other.other_child import Child
def make_child() -> Child:
return Child()
[file other/__init__.py]
from other.other_child import Child as Child
from other.other_subpkg import Base as Base
[file other/other_child.py]
from other.other_subpkg import Base
class Child(Base):
pass
[file other/other_subpkg/__init__.py]
from other.other_subpkg.other_base import Base as Base
[file other/other_subpkg/other_base.py]
class Base:
def __eq__(self, other: object) -> bool:
return True
[file driver.py]
from native import make_child
left = make_child()
right = make_child()
assert left == right
assert not (left != right)
create_ne_from_eq() checks whether the class has an __eq__ method using cls.has_method("__eq__"), but gen_glue_ne_method() then requires cls.get_method("__eq__") to return a concrete FuncIR.
In this package-cycle case, the inherited method declaration exists, but the concrete FuncIR body is not available yet. This makes cls.has_method("__eq__") true while cls.get_method("__eq__") returns None.
Activity
rheard commentedon May 30, 2026
Cause
create_ne_from_eq()checks whether the class has an__eq__method usingcls.has_method("__eq__"), butgen_glue_ne_method()then requirescls.get_method("__eq__")to return a concrete FuncIR.In this package-cycle case, the inherited method declaration exists, but the concrete
FuncIRbody is not available yet. This makescls.has_method("__eq__")true whilecls.get_method("__eq__")returns None.[mypyc] Use `method_sig` to get the method signature (#21567)