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

Make paasta without args compat with py3 #1428

Merged
merged 2 commits into from
Aug 14, 2017
Merged

Make paasta without args compat with py3 #1428

merged 2 commits into from
Aug 14, 2017

Conversation

solarkennedy
Copy link
Contributor

No description provided.

@solarkennedy solarkennedy self-assigned this Aug 3, 2017
@asottile
Copy link
Contributor

asottile commented Aug 3, 2017

The usual fix for this is subparsers.required = True (at least in a 2+3 compatible codebase)

@solarkennedy
Copy link
Contributor Author

Second attempt with required=true

@@ -84,6 +84,10 @@ def get_argparser():
)

subparsers = parser.add_subparsers(help="[-h, --help] for subcommand help")
subparsers.required = True
# https://stackoverflow.com/questions/18282403/argparse-with-required-subcommands/18283730#18283730
subparsers.dest = 'command'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a keyword to add_subparsers (but .required cannot for some reason, maybe I'll make a PR to stdlib to enable this). Here's an example from pre-commit (note that pre-commit avoids needing .required = true due to some other hax that I wouldn't suggest (it implements a "default" command))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True to my word, here's the cpython PR: python/cpython#3027

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Till we upgrade to a version of python with that PR, then I should ship what I have as is, correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move dest='command' as a kwarg to add_subparsers, but you won't be able to move .required = ... until then.

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 this pull request may close these issues.

2 participants