WIP: Require an automatic parameter name to be a Python identifier - #3827
WIP: Require an automatic parameter name to be a Python identifier#3827kdeldycke wants to merge 1 commit into
Conversation
|
Both of these seem like bugs. I feel like the automatic names should always be normalized and pass |
254d9e4 to
49a5f5a
Compare
OK cool, that was also my feeling. We don't want special treatments of the |
49a5f5a to
ad8601c
Compare
Argument name to be a Python identifier
@davidism Done. I did not pushed the normalization too much. So there is one bothering difference between |
Argument name to be a Python identifierArgument name to be a Python identifier
05c4439 to
3d4142f
Compare
Argument name to be a Python identifierArgument and Option automatic naming
|
I just pushed the alignment and normalization of naming a bit more and updated the differences in the body of that PR. |
3d4142f to
b4606f9
Compare
Argument and Option automatic namingb4606f9 to
ff79a3c
Compare
|
OK these were my final edits. You can review this PR. |
ff79a3c to
6f9943e
Compare
|
This needs to be targeted at 9.0 and listed high up in the changelog, the name normalization is a breaking change. Along with the keyword check I mention below, this could be significantly disruptive. We should probably issue a deprecation warning and accept names that are currently accepted, before applying the new rules. It might be good for the Overall I think the docs are a little too verbose about this. Giving a few examples and linking to You bring up a good point about keywords. I think the intention of this code was clear: to only accept names that can be used in signatures rather than |
Rowlando13
left a comment
There was a problem hiding this comment.
I agree with @davidism. The docs are too verbose and these changes should go through normal deprecation process. Probably a best course of action is to make a pr against stable that has whatever tests you think we should have to lock in existing behavior. Then can merge stable into main. And you can make the new pr against main with the deprecations.
|
Ahah agreed 100% about the verbosity of the docs. They accumulates all my changes and discovery through the process of producing this PR. It was a way for me to highlight how clunky the ID derivation is at the moment. My thinking being that if I can write the docs easily and make them flow naturally, it probably means the underlying concept and implementation is clean. Ok for a 9.0.0 target then. What I will do:
|
6f9943e to
127ed65
Compare
Problem is the list of Python keywords would prevent some options like |
|
OK so I think I am done with this PR and it now implements the ideal target behavior for 9.0.0. I will now create in the next few days a sibling PR for 8.5.1/8.6.0 that detects the changes and emits deprecation warnings. If I discover new stuff while producing this other PR I might bring some changes here. |
Click 9.0 refuses such a name; warn a release ahead so the break can diffuse. Prepares the ground for #3827, as promised in pull/3827#issuecomment-5583963038.
Click 9.0 refuses such a name; warn a release ahead so the break can diffuse. Prepares the ground for pallets#3827, as promised in pull/3827#issuecomment-5583963038.
Prepares the ground for pallets#3827 and future 9.0.0 release
Prepares the ground for pallets#3827 and future 9.0.0 release
127ed65 to
0054c44
Compare
This PR changes the behavior of automatic naming:
0-file,foo.barandfoo barare now refused.expose_value=Falseno longer bypasses that check, on both arguments and options.click.argument(expose_value=False)andclick.option(expose_value=False)used to produce a""parameter.click.option("--in-file", "Input_File")names its parameterinput_file.What does not change:
-becomes_and the result is lower cased.click.option("--0-file").How to migrate:
click.option("--0-file", "zero_file").metavarto keep the old display:click.argument("zero_file", metavar="0-FILE").This PR shares the majority of the tests from #3866 which lockdown all other edge-cases and canonical naming behavior.
This PR is waiting for #3866 to be merged into the 8.x release cycle to be rebased on it.
Context
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).
Note: this PR started as simple test coverage expansion but ended up implementing sanitizing fixes.