Skip to content

mypyc assertion error when generating __ne__ from inherited __eq__ in package import cycle #21566

Closed

Description

@rheard

Bug Report

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)

Run:

python -m pytest -q mypyc/test/test_run.py -k testPackageCycleInheritedEq

Expected Behavior

mypyc should compile this successfully.

Since Child inherits Base.__eq__ but does not define __ne__, mypyc should be able to synthesize Child.__ne__ from the inherited __eq__ declaration.

Actual Behavior

mypyc fails with an internal assertion error while generating __ne__:

mypyc/irbuild/classdef.py:...: in gen_glue_ne_method
    assert func_ir
AssertionError

Activity

  1. rheard commented on May 30, 2026

    @rheard
    ContributorAuthor

    Cause

    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.

  2. added a commit that references this issue on Jun 1, 2026
    70b74e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions