argparse: Make short flag names optional#7585
Merged
Merged
argparse: Make short flag names optional#7585
Conversation
It was always a bit ridiculous that argparse required X-longflag if that "X" was never actually used anywhere. Since the short letter is for getopt's benefit, we can hack around this with our old friend: Unicode Private Use Areas. We have a counter, starting at 0xE000 and going to 0xF8FF, that counts up for all options that don't have a short flag and provides one. This gives us up to 6400 long-only options. 6.4K should be enough for everybody.
faho
force-pushed
the
argparse-longonly
branch
from
December 28, 2020 19:20
65f7ffe to
2867d64
Compare
zanchey
reviewed
Dec 29, 2020
zanchey
left a comment
Member
There was a problem hiding this comment.
Seems like a sensible thing to do!
Member
|
I couldn't see anything obvious in |
Member
Author
Tests show that it works (the test passes), and we only really need to represent some opaque values as wchar, so locale doesn't really apply - the width of a wchar is constant (and since we're under FFFF we should be okay with 2-byte wchar IIUC). (technically we should check if any of the provided short flags is a PUA codepoint - or do we reject those on input anyway?) |
krobelus
approved these changes
Dec 29, 2020
This previously allowed `#-long`, but the `-` isn't needed - just `#long` is enough.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It was always a bit ridiculous that argparse required X-longflag if
that "X" was never actually used anywhere.
Since the short letter is for getopt's benefit, we can hack around
this with our old friend: Unicode Private Use Areas.
We have a counter, starting at 0xE000 and going to 0xF8FF, that counts
up for all options that don't have a short flag and provides one. This
gives us up to 6400 long-only options.
6.4K should be enough for everybody.
TODOs: