Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Incorrect overalp detected in __rmod__ with str argument #7402

Closed
@zero323

Description

@zero323

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], whereT can 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 overlapping

Issue 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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp