Skip to content

argparse.parse_args should have a generic return type #2366

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

Closed
keysmashes opened this issue Aug 7, 2018 · 0 comments · Fixed by #2566
Closed

argparse.parse_args should have a generic return type #2366

keysmashes opened this issue Aug 7, 2018 · 0 comments · Fixed by #2566

Comments

@keysmashes
Copy link
Contributor

(sorry if generic is the wrong word to describe this)

argparse.parse_args(namespace=MyNamespace()) returns an instance of MyNamespace, but it's annotated to always return an argparse.Namespace. This means that in order to have type-safety when accessing arguments by using a custom type-annotated class:

class Arguments:
    verbose: bool
    ...
args = argparse.parse_args(namespace=Arguments())

you currently need to cast the return value of argparse.parse_args.

Also, the passed object doesn't actually have to be a (subclass of) argparse.Namespace – a simple subclass of object is documented to work.

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

Successfully merging a pull request may close this issue.

2 participants