Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Description
Problem observed using current HEAD (0.730+dev.d2a7f05d27d9ac5c096c61ecf0455edda91f5d5a) but can confirmed on 0.660 as well, so it is nothing new.
Flags used:
--python-version 3.7 --strict-optional --no-site-packages --show-traceback --no-implicit-optional- Also confirmed with no flags at all (Python 3.7)
Problem occurs:
- With
__mod__/__rmod__pair. - When other in
__mod__isUnion[T, str], whereTcan be self type, or some other type (let's sayint). - When other in
__rmod__isstr. - When return type annotation for
__rmod__is provided,
Reproducible example:
fromtypingimportUnionclassFoo:def__mod__(self,other:Union[Foo,str])->Foo: ...def__rmod__(self,other:str)->Foo: ...
yields
foo.py:5: error: Signatures of "__rmod__" of "Foo" and "__mod__" of "str" are unsafely overlappingIssue is specific to__mod__ /__rmod__ pair, i.e. this works just fine:
fromtypingimportUnionclassFoo:def__mul__(self,other:Union[Foo,str])->Foo: ...def__rmul__(self,other:str)->Foo: ...
and I haven't found any other problematic pair.
As far as I can tell it strictly depends onother beingstr. For example this works just fine
fromtypingimportUnionclassFoo:def__mod__(self,other:Union[Foo,int])->Foo: ...def__rmod__(self,other:int)->Foo: ...
Additionally, to reproduce the problem, we need a return type annotation on__rmod__, and removing it is sufficient to pass type check (removing return type annotation from__mod__ has no impact at all):
fromtypingimportUnionclassFoo:def__mod__(self,other:Union[Foo,str])->Foo: ...def__rmod__(self,other:str): ...
though failure is not specifically caused by referencing self type, as for example this, will fail as well
fromtypingimportUnionclassFoo:def__mod__(self,other:Union[Foo,str])->int: ...def__rmod__(self,other:str)->int: ...
foo.py:5: error: Signatures of "__rmod__" of "Foo" and "__mod__" of "str" are unsafely overlapping