Skip to content

Require an Argument name to be a Python identifier - #3827

Draft
kdeldycke wants to merge 1 commit into
pallets:stablefrom
kdeldycke:param-name-case-coverage
Draft

Require an Argument name to be a Python identifier#3827
kdeldycke wants to merge 1 commit into
pallets:stablefrom
kdeldycke:param-name-case-coverage

Conversation

@kdeldycke

Copy link
Copy Markdown
Collaborator

This PR lockdown edge-cases and surprising behavior in the way Click transform arguments and options specifications and determine their canonical names.

It is in the same vein as my previous PR at #3808 , and is also based on a collection of edge-cases I accumulated over the years. It also covers platform differences between Windows and Unix-like (see: #2483).

This PR does not change the behavior of Click: it only add unitests and public documentation. I don't like some of the cases highlighted here, but I'll refrain from suggesting any change or refactoring. I'll leave that for future exploration and debates in 8.x or even 9.x releases.

Unless other maintainers point to some cases being obviously wrong and that needs fixes. In which case I'll be happy to address them.

@kdeldycke kdeldycke added this to the 8.5.1 milestone Sep 1, 2026
@kdeldycke kdeldycke added docs Updates to documentation, readme, docstrings, typos tests Click's own test suite and CI workflows labels Sep 1, 2026
@davidism

davidism commented Sep 1, 2026

Copy link
Copy Markdown
Member

Both of these seem like bugs. I feel like the automatic names should always be normalized and pass str.isidentifier.

@kdeldycke
kdeldycke force-pushed the param-name-case-coverage branch from 254d9e4 to 49a5f5a Compare September 1, 2026 14:43
@kdeldycke

Copy link
Copy Markdown
Collaborator Author

Both of these seem like bugs. I feel like the automatic names should always be normalized and pass str.isidentifier.

OK cool, that was also my feeling. We don't want special treatments of the name of parameters, whatever their kind (options or arguments). I cannot find any reasons with the transformation should be different between the two kinds. So in the end yes, str.isidentifier should be the minimal check common to the two.

@kdeldycke kdeldycke changed the title Cover edge-cases of parameter's naming WIP: Cover edge-cases of parameter's naming Sep 1, 2026
@kdeldycke
kdeldycke marked this pull request as draft September 1, 2026 14:44
@kdeldycke
kdeldycke force-pushed the param-name-case-coverage branch from 49a5f5a to ad8601c Compare September 1, 2026 22:15
Aligns the constraints to `Option`'s
@kdeldycke kdeldycke changed the title WIP: Cover edge-cases of parameter's naming WIP: Require Argument's naming to be a Python identifier Sep 1, 2026
@kdeldycke kdeldycke changed the title WIP: Require Argument's naming to be a Python identifier WIP: Require an Argument name to be a Python identifier Sep 1, 2026
@kdeldycke

Copy link
Copy Markdown
Collaborator Author

Both of these seem like bugs. I feel like the automatic names should always be normalized and pass str.isidentifier.

@davidism Done. I did not pushed the normalization too much.

So there is one bothering difference between Argument and Option: the latter makes click.option("--in-file", "Input_File") names its parameter Input_File, while Argument forces it to input_file. Should I align both? I would tend to yes.

@kdeldycke kdeldycke changed the title WIP: Require an Argument name to be a Python identifier Require an Argument name to be a Python identifier Sep 1, 2026
@kdeldycke
kdeldycke force-pushed the param-name-case-coverage branch from ad8601c to 3e5301b Compare September 1, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Updates to documentation, readme, docstrings, typos tests Click's own test suite and CI workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing auto-generated environment variables in help screen & case-sensitivity

2 participants