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

[3.11] gh-60346: Improve handling single-dash options in ArgumentParser.parse_known_args() (GH-114180) #115674

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Feb 19, 2024

(cherry picked from commit e47ecbd)

Co-authored-by: Serhiy Storchaka storchaka@gmail.com

…r.parse_known_args() (pythonGH-114180)

(cherry picked from commit e47ecbd)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@Erotemic
Copy link

Noting that adding a sep to the option_tuple broke my ArgumentParser extension which allows for flags to be insensitive to being specified as --foo-bar=123 or --foo_bar=123. Ultimately, it's my bad for overloading a non-public API, but it would've been nice if option tuple stayed consistent. Given that it already changed, it may be worth changing the option-tuple from a tuple to a namedtuple so the arguments can be unpacked explicitly rather than relying on the ordering of the tuple. I'm scratching my head wondering how I'm going to patch scriptconfig to handle this case.

What is the patch version of 3.11 that this was introduced in? 3.11.9?

@serhiy-storchaka
Copy link
Member

Yes, in 3.11.9. You perhaps can just check the length of the tuple.

I think a named tuple is an overhead for a deeply internal API. It is just a way to return multiple values from a function.

Perhaps we could consider an idea of adding more general public API to solve your problem. For example, the ability to add hidden aliases or to transform options before comparison, so --foo-bar and /FOOBAR could be different spellings of the same option. Or simply ignore the difference between '-' and '_' in option names by default, since '-' is already translated to '_' in inferred destination. But these are different issues.

@bebound
Copy link

bebound commented Apr 25, 2024

This change also broke argcomplete.
Related issue: kislyuk/argcomplete#481
Fixed in 3.3.0: kislyuk/argcomplete@54a4846

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.

None yet

4 participants