GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mypyc assertion error when generating `__ne__` from inherited `__eq__` in package import cycle · Issue #21566 · python/mypy

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

New issue
Copy link
New issue
Copy link
Closed
#21567
Closed
mypyc assertion error when generating __ne__ from inherited __eq__ in package import cycle#21566
#21567
Copy link
Labels
bugmypy got something wrong

Description

@rheard
rheard
opened on May 30, 2026
Issue body actions

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
    added
    bugmypy got something wrong
    on May 30, 2026
  2. rheard commented on May 30, 2026

    @rheard
    rheard
    on May 30, 2026
    ContributorAuthor
    More actions

    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.

  3. p-sawicki
    closed this as completedin #21567on Jun 1, 2026
  4. p-sawicki
    added a commit that references this issue on Jun 1, 2026

    [mypyc] Use `method_sig` to get the method signature (#21567)

    This issue will close once commit 70b74e1 is merged into the 'master' branch.
    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

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.