mypyc assertion error when generating `__ne__` from inherited `__eq__` in package import cycle
bug
**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
```
**Your Environment**
- Mypy version used: Built from latest commit in master.
- Mypy command-line flags: Irrelevant. See provided test. Fix incoming.
- Mypy configuration options from `mypy.ini` (and other config files): None
- Python version used: Python 3.12
1 条评论