Skip to content

Error in code using map with os.fspath on a list of strings #2959

Description

@dalcinl

Summary

Reproducer

# repro.py
import os
map(os.fspath, ["a", "b"])

Error

$ ty check repro.py 
error[invalid-argument-type]: Argument to function `__new__` is incorrect
 --> repro.py:2:5
  |
1 | import os
2 | map(os.fspath, ["a", "b"])
  |     ^^^^^^^^^ Expected `(str | bytes | Unknown, /) -> str | bytes | Unknown`, found `Overload[(path: str) -> str, (path: bytes) -> bytes, [AnyStr](path: PathLike[AnyStr]) -> AnyStr]`
  |
info: Matching overload defined here
    --> stdlib/builtins.pyi:3866:13
     |
3864 |     else:
3865 |         @overload
3866 |         def __new__(cls, func: Callable[[_T1], _S], iterable: Iterable[_T1], /) -> Self: ...
     |             ^^^^^^^      ------------------------- Parameter declared here
3867 |         @overload
3868 |         def __new__(cls, func: Callable[[_T1, _T2], _S], iterable: Iterable[_T1], iter2: Iterable[_T2], /) -> Self: ...
     |
info: Non-matching overloads for function `__new__`:
info:   [_T1, _T2, Self](cls, func: (_T1, _T2, /) -> _S@map, iterable: Iterable[_T1], iter2: Iterable[_T2], /) -> Self
info:   [_T1, _T2, _T3, Self](cls, func: (_T1, _T2, _T3, /) -> _S@map, iterable: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], /) -> Self
info:   [_T1, _T2, _T3, _T4, Self](cls, func: (_T1, _T2, _T3, _T4, /) -> _S@map, iterable: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], /) -> Self
info:   [_T1, _T2, _T3, _T4, _T5, Self](cls, func: (_T1, _T2, _T3, _T4, _T5, /) -> _S@map, iterable: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], iter4: Iterable[_T4], iter5: Iterable[_T5], /) -> Self
info:   [Self](cls, func: (...) -> _S@map, iterable: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], /, *iterables: Iterable[Any]) -> Self
info: rule `invalid-argument-type` is enabled by default

Found 1 diagnostic

Version

ty 0.0.20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions