Skip to content

Wrong overload item picked when strict optional disabled #5238

@JukkaL

Description

@JukkaL

When type checking the following two files, the revealed type is unicode though I'd expect str -- but only when using -2 --no-strict-optional:

# t.py
from typing import Optional
from m import relpath
a = '' # type: Optional[str]
reveal_type(relpath(a))  # unicode
# m.py
from typing import overload
@overload
def relpath(path: str) -> str: ...
@overload
def relpath(path: unicode) -> unicode: ...

The issue also happens with os.path.relpath.

To reproduce:

$ mypy -2 --no-strict-optional t.py
t.py:4: error: Revealed type is 'builtins.unicode'

The issue seems to be related to using an optional type in a file which doesn't use strict optional checking.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions