-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed as not planned
Labels
as designedNot a bug, working as intendedNot a bug, working as intendedbugSomething isn't workingSomething isn't working
Description
The shutil.move function is defined in the typeshed as:
def move(src: StrPath, dst: StrPath, copy_function: _CopyFn = ...) -> _PathReturn: ...... where StrPath is an alias of str | os.PathLike[str] and _PathReturn is an alias of Any.
Previously, pyright would not attempt to synthesise the return type and move would consistently return Any. As of 1.1.399, the dst parameter appears to act like a type variable and the return type of move is the union of _PathReturn, str and the type accepted by PathLike:
$ cat test.py
import typing
from pathlib import Path
from shutil import move
typing.reveal_type(move)
typing.reveal_type(move('abc', 'def'))
typing.reveal_type(move(Path('abc'), Path('def')))
$ npx -y pyright@1.1.398 test.py
/[...]/test.py
/[...]/test.py:5:20 - information: Type of "move" is "(src: str | PathLike[str], dst: str | PathLike[str], copy_function: ((str, str) -> object) | ((str | PathLike[str], str | PathLike[str]) -> object) = ...) -> Any"
/[...]/test.py:6:20 - information: Type of "move('abc', 'def')" is "Any"
/[...]/test.py:7:20 - information: Type of "move(Path('abc'), Path('def'))" is "Any"
0 errors, 0 warnings, 3 informations
$ npx -y pyright test.py
/[...]/test.py
/[...]/test.py:5:20 - information: Type of "move" is "(src: str | PathLike[str], dst: _StrPathT@move, copy_function: ((str, str) -> object) | ((str | PathLike[str], str | PathLike[str]) -> object) = ...) -> (_StrPathT@move | str | Any)"
/[...]/test.py:6:20 - information: Type of "move('abc', 'def')" is "str | Any"
/[...]/test.py:7:20 - information: Type of "move(Path('abc'), Path('def'))" is "Path | str | Any"
0 errors, 0 warnings, 3 informations
This is surprising and does not reflect how move behaves at runtime.
Metadata
Metadata
Assignees
Labels
as designedNot a bug, working as intendedNot a bug, working as intendedbugSomething isn't workingSomething isn't working