Skip to content

Deprecate parameter names that are: not a Python identifier, or a Python Keyword, or not lower-cased - #3866

Merged
Rowlando13 merged 2 commits into
pallets:mainfrom
kdeldycke:deprecate-non-identifier-names
Sep 23, 2026
Merged

Rowlando13 merged 2 commits into
pallets:mainfrom
kdeldycke:deprecate-non-identifier-names

Conversation

@kdeldycke

@kdeldycke kdeldycke commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

This PR prepares the ground for #3827, which is going to refuse parameter names that are not valid Python identifiers.

This add DeprecationWarning that detect when Parameter, Argument or Option gets a name that will be not allowed in the future 9.0.0 release:

  • a parameter that is not a Python identifier (check against str.identifier)
  • a parameter that is a Python keyword (check against keyword.iskeyword)
  • an option name that is nor lower-cased

This PR also copy the majority of tests that were originally proposed in #3827, so the behavior of the name is locked down and frozen. This will prevent tweaking or introducing regressions during the full 8.x cycle.

This PR also inaugurate the 8.6.0 release on main.

Historical details

Of course, I fucked-up the same way I fucked-up 2 months ago with #3701 , when juggling between main and stable branches made me push to stable. 😫

So:

  • I pushed by mistake e2bddbc
  • I reverted my mistake on stable with d036881
  • And this PR is what it should have been all along

Anyway, this was resolved by resyncing both branches with #3876 .

@kdeldycke kdeldycke added the parsing Parsing, parameters, commands, chaining, context label Sep 11, 2026
@kdeldycke kdeldycke added this to the 8.5.1 milestone Sep 11, 2026
@kdeldycke kdeldycke added the tests Click's own test suite and CI workflows label Sep 11, 2026
@kdeldycke
kdeldycke force-pushed the deprecate-non-identifier-names branch from 62cff1d to 3c5be86 Compare September 11, 2026 13:35
@davidism

Copy link
Copy Markdown
Member

What do you think, should we also check keyword.iskeyword? Might be good to warn about it and see if anything comes up.

@kdeldycke

Copy link
Copy Markdown
Collaborator Author

What do you think, should we also check keyword.iskeyword? Might be good to warn about it and see if anything comes up.

Ah. That might be a good idea: test drive that check during a long 8.x cycle and see if it show up... If I implement this, what kind of severity should it triggers? A DeprecationWarning like non-Python-IDs ?

@davidism

Copy link
Copy Markdown
Member

Deprecation seems fine. Like I said in the other thread, it could be more disruptive, but it also seems to match the intention of the str.isidentifier check.

@kdeldycke
kdeldycke force-pushed the deprecate-non-identifier-names branch from 3c5be86 to eb37bea Compare September 11, 2026 14:24
@kdeldycke
kdeldycke force-pushed the deprecate-non-identifier-names branch from eb37bea to a5af540 Compare September 21, 2026 10:57
@kdeldycke

Copy link
Copy Markdown
Collaborator Author

Just implemented the double isidentifier() / iskeyword() deprecation check in a common _check_name_is_usable() internal function. The later is maybe a bit too verbose as I distinguished the 2 cases and reused the deprecation explanation from docs/upgrade-guides.md. Can make it way smaller if you want to.

This is ready to be reviewed for eventual merge.

@kdeldycke kdeldycke changed the title Deprecate a parameter name that is not a Python identifier Deprecate parameter names that are: not a Python identifier, or a Python Keyword, or not lower-cased Sep 21, 2026
kdeldycke added a commit to kdeldycke/click-extra that referenced this pull request Sep 21, 2026
Click is about to get a similar stack-level inspection utility in pallets/click#3866.
@Rowlando13

Copy link
Copy Markdown
Member

@kdeldycke this should merge into main. I don't we should issue new deprecations on bug fix versions.

@kdeldycke
kdeldycke changed the base branch from stable to main September 22, 2026 06:27
@kdeldycke kdeldycke modified the milestones: 8.5.1, 8.6.0 Sep 22, 2026
@kdeldycke
kdeldycke force-pushed the deprecate-non-identifier-names branch from a5af540 to b90faad Compare September 22, 2026 06:48
@kdeldycke

Copy link
Copy Markdown
Collaborator Author

@kdeldycke this should merge into main. I don't we should issue new deprecations on bug fix versions.

OK make sense. So I retargeted the main branch, added a new commit in this PR to inaugurate the 8.6.0 release and updated the doc to target that release. And this time I hope I did not made any mistake juggling with the two branches... 🫣

@Rowlando13
Rowlando13 merged commit 06b2a67 into pallets:main Sep 23, 2026
12 checks passed
@kdeldycke
kdeldycke deleted the deprecate-non-identifier-names branch September 23, 2026 04:51
kdeldycke added a commit to kdeldycke/click that referenced this pull request Sep 23, 2026
Make `DeprecationWarning` from pallets#3866 into `TypeError`
kdeldycke added a commit to kdeldycke/click that referenced this pull request Sep 23, 2026
Make `DeprecationWarning` from pallets#3866 into `TypeError`
kdeldycke added a commit to kdeldycke/click that referenced this pull request Oct 5, 2026
Make `DeprecationWarning` from pallets#3866 into `TypeError`
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

parsing Parsing, parameters, commands, chaining, context tests Click's own test suite and CI workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants