-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type inference issue with "map" and "os.path.normcase" #8961
Comments
VScode correctly identifies the sig when you hover: This works: import os
def fn(s: str) -> str:
return os.path.normpath(s)
files = ['foo/BAR', 'FOO/baz']
normcased_files = map(fn, files)
reveal_type(os.path.normpath)
# note: Revealed type is 'Overload(def [AnyStr in (builtins.str, builtins.bytes)] (path: builtins._PathLike[AnyStr`-1]) -> AnyStr`-1, def [AnyStr in (builtins.str, builtins.bytes)] (path: AnyStr`-1) -> AnyStr`-1)'
reveal_type(fn)
# note: Revealed type is 'def (x: builtins.str) -> builtins.str' |
You can do this as a one line workaround: normcased_files = map(lambda x: os.path.normpath(x), files) And if you care about the type: from typing import List
normcased_files: List[str] = list(map(lambda x: os.path.normpath(x), files)) |
With regards to the comment on #8962, since the |
Thanks. I was aware of the workaround, but that's not the actual problem here. The original code should also pass type checks.
No, that doesn't work either
|
Closing as a duplicate of #2389 (although the example is slightly different, the bug appears to be to be the same) |
The following code raises a type error when run with
mypy v0.780
.The errors are as follows
Note that the error is different when run against python 2 vs python 3, even when the type annotations are same for both python 3 and python 2
The text was updated successfully, but these errors were encountered: