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

Trim trailing _ from argument names #222

Open
djpohly opened this issue Feb 5, 2024 · 0 comments
Open

Trim trailing _ from argument names #222

djpohly opened this issue Feb 5, 2024 · 0 comments
Assignees
Milestone

Comments

@djpohly
Copy link

djpohly commented Feb 5, 2024

Is your feature request related to a problem?

There doesn't appear to be a way to have an argument with the same name as a keyword, and it may also be undesirable to shadow a builtin. For example, if you were implementing a Git command:

def rev_list(*, not: bool = False, all: bool = False):
    ...

you would get a SyntaxError on not, and you'd have to use builtins.all explicitly in the body of the function. It seems from the operator module that the conventional way to avoid this problem is to append an underscore (as in operator.not_).

Describe the solution you'd like

I'd suggest trimming a trailing underscore from the declared names of arguments (name = name.removesuffix("_")) prior to processing. Readability would only be minimally affected:

def rev_list(*, not_: bool = False, all_: bool = False):
    ...

It seems very unlikely that someone would want to create a command-line option with a trailing dash, but it could still be accomplished by adding a second underscore.

Describe alternatives you've considered

The arg decorator could accept an argname= parameter to allow for arbitrary naming of command arguments, but that seemed to provide too much of an opportunity to harm readability, and it would probably be more complicated to implement.

Additional context

The solution to this may or may not be related to #220, since both involve alternative ways to name arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants