-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: 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.
65f7ffe
to
2867d64
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a sensible thing to do!
I couldn't see anything obvious in |
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?) |
This previously allowed `#-long`, but the `-` isn't needed - just `#long` is enough.
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: