GeezerVison is showing github.com — [mypyc] Use `method_sig` to get the method signature (#21567) · python/mypy@70b74e1
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: mypyc/irbuild/classdef.py +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -862,9 +862,7 @@ def create_ne_from_eq(builder: IRBuilder, cdef: ClassDef) -> None: |
862 | 862 |
|
863 | 863 | def gen_glue_ne_method(builder: IRBuilder, cls: ClassIR, line: int) -> None: |
864 | 864 | """Generate a "__ne__" method from a "__eq__" method.""" |
865 | | - func_ir = cls.get_method("__eq__") |
866 | | - assert func_ir |
867 | | - eq_sig = func_ir.decl.sig |
| 865 | + eq_sig = cls.method_sig("__eq__") |
868 | 866 | strict_typing = builder.options.strict_dunders_typing |
869 | 867 | with builder.enter_method(cls, "__ne__", eq_sig.ret_type): |
870 | 868 | rhs_type = eq_sig.args[0].type if strict_typing else object_rprimitive |
|
Collapse file
Copy file name to clipboardExpand all lines: mypyc/test-data/run-multimodule.test +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1710,6 +1710,41 @@ assert sum_range(0) == 0 |
1710 | 1710 | assert sum_range(1) == 0 |
1711 | 1711 | assert sum_range(5) == 10 |
1712 | 1712 |
|
| 1713 | +[case testPackageCycleInheritedEq] |
| 1714 | +-- Regression test for generating __ne__ from an inherited __eq__ when the |
| 1715 | +-- inherited method's declaration is available before its FuncIR body has been |
| 1716 | +-- generated. This can happen in package import cycles where __init__ imports a |
| 1717 | +-- child module before the subpackage that defines the base class. |
| 1718 | +from other.other_child import Child |
| 1719 | + |
| 1720 | +def make_child() -> Child: |
| 1721 | + return Child() |
| 1722 | + |
| 1723 | +[file other/__init__.py] |
| 1724 | +from other.other_child import Child as Child |
| 1725 | +from other.other_subpkg import Base as Base |
| 1726 | + |
| 1727 | +[file other/other_child.py] |
| 1728 | +from other.other_subpkg import Base |
| 1729 | + |
| 1730 | +class Child(Base): |
| 1731 | + pass |
| 1732 | + |
| 1733 | +[file other/other_subpkg/__init__.py] |
| 1734 | +from other.other_subpkg.other_base import Base as Base |
| 1735 | + |
| 1736 | +[file other/other_subpkg/other_base.py] |
| 1737 | +class Base: |
| 1738 | + def __eq__(self, other: object) -> bool: |
| 1739 | + return True |
| 1740 | + |
| 1741 | +[file driver.py] |
| 1742 | +from native import make_child |
| 1743 | +left = make_child() |
| 1744 | +right = make_child() |
| 1745 | +assert left == right |
| 1746 | +assert not (left != right) |
| 1747 | + |
1713 | 1748 | [case testSeparateCrossGroupInheritedInit] |
1714 | 1749 | -- Under separate=True, a subclass whose __init__ is inherited from a |
1715 | 1750 | -- different group must call the base's CPyPy_ wrapper through the exports |
|