Mypyc apprently ignores custom __new__ methods without warning. It would be great if it could abide by the custom __new__, but otherwise a warning / error should be raised.
Example code (see #1020 (comment)):
from __future__ importannotationsclassAdd:
l: IntLiker: IntLikedef__new__(cls, l: IntLike, r: IntLike) ->IntLike: # type: ignore[misc]print(f'running __new__ with {l} and {r}')
return (
lifr==0elserifl==0elsesuper().__new__(cls)
)
def__init__(self, l: IntLike, r: IntLike):
self.l=lself.r=rdef__repr__(self) ->str:
returnf'({self.l} + {self.r})'def__add__(self, other: IntLike) ->IntLike:
returnAdd(self, other)
IntLike=int|AddCode for running:
print(f'{Add(1, 5)=}')
print(f'{Add(0, 5)=}')
print(f'{Add(1, 0)=}')Running this interpreted gives:
running __new__ with 1 and 5
Add(1, 5)=(1 + 5)
running __new__ with 0 and 5
Add(0, 5)=5
running __new__ with 1 and 0
Add(1, 0)=1
Running compiled:
Add(1, 5)=(1 + 5)
Add(0, 5)=(0 + 5)
Add(1, 0)=(1 + 0)
The interpreted and compiled behaviors are different, which is bad.
Mypyc apprently ignores custom
__new__methods without warning. It would be great if it could abide by the custom__new__, but otherwise a warning / error should be raised.Example code (see #1020 (comment)):
Code for running:
Running this interpreted gives:
Running compiled:
The interpreted and compiled behaviors are different, which is bad.