Skip to content
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 #7177

Closed
andymwood opened this issue Jul 9, 2019 · 2 comments
Closed

Comments

@andymwood
Copy link

Running mypy on this code:

import argparse,  os
reveal_type(os.path.abspath)
p = argparse.ArgumentParser()
p.add_argument("file", type=os.path.abspath)

I get:

mypy args.py 
args.py:2: 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)'
args.py:4: error: Argument "type" to "add_argument" of "_ActionsContainer" has incompatible type overloaded function; expected "Union[Callable[[str], AnyStr], FileType]"

I originally thought this might be an issue with typeshed and reported it here, but it turns out that pytype accepts the code.

@ilevkivskyi
Copy link
Member

It seems to me the mypy problem here is a duplicate of #1317.

But there is also a typeshed issue IMO (fixing which will fix this issue), so you might want to open an issue there. The add_argument method is needlessly generic, replacing _T with Any there will not reduce the strictness of the method.

cc @JelleZijlstra

@andymwood
Copy link
Author

But there is also a typeshed issue IMO (fixing which will fix this issue), so you might want to open an issue there.

I originally reported the issue here but was told it was probably a mypy issue. I'll re-open that issue and let you guys fight it out amongst yourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants