-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
argparse.ArgumentParser.add_argument doesn't allow type=os.path.abspath #3107
Comments
I assume you are using Python 3.6+. If I'm not mistaken, the stubs are correct. |
Ok, thanks for that. I've reported the issue at the python/mypy repo instead. |
I'm re-opening this issue following the advice of this comment. |
I still think from argparse import ArgumentParser
def to_str(x: str) -> str:
return x
arg = ArgumentParser()
arg.add_argument(type=to_str, choices=[1]) CC @ilevkivskyi |
The fact that mypy currently flags above code is a bug in mypy (quite subtle one). It should infer For example this code is correctly accepted: T = TypeVar('T')
def g(x: T, y: T) -> None: ...
g('yes', 42) |
Pyright allows the code in the original post and it also looks fine to me with the current stub, so I am going to say this is still a bug in mypy. |
Running mypy on this code:
I get:
Should the type signature of
add_argument
be changed to allow functions that accept aPathLike
argument?The text was updated successfully, but these errors were encountered: