-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
def f() -> AnyStr fails if f returns a str #7180
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
Comments
Did you mean to use |
Thanks for that. It seems I'd misunderstood something. However, there's another possible bug which might have misled me into using The following is closer to what I was originally trying to do: import os
from typing import Dict, Iterable
def get_files() -> Iterable[os.DirEntry]:
for f in os.scandir():
yield f
def get_dict() -> Dict[str, str]:
return {"a": "b"}
files = get_files()
x = get_dict()
for key in map(os.path.realpath, files):
val = x.get(key)
print(key, val) mypy returns this error:
The error goes away if I change
|
I think this is because you're missing a type argument on |
Following your advice, I get this: mypy --disallow-any-generics anystr.py
anystr.py:16: error: Argument 1 to "map" has incompatible type overloaded function; expected "Callable[[DirEntry[str]], AnyStr]"
anystr.py:17: error: Argument 1 to "get" of "Mapping" has incompatible type "AnyStr"; expected "str" |
The original problem is not a bug, as Jelle explained. The second issue is a duplicate of #1317, passing one generic function ( |
I expect mypy to allow the following code to pass:
Instead, I get this:
I'm using Python 3.6 and mypy 0.711
The text was updated successfully, but these errors were encountered: