-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix default handling to defer UNSET normalization
#3079
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
Fix default handling to defer UNSET normalization
#3079
Conversation
|
Your unit tests clearly demonstrate the issue and your changes don't trigger any other tests covering the I'm pretty sure there is a more elegant way to solve it but for inclusion in a 8.3.1 hotfix release, this is good to me. We'll have plenty of time to refactor the code later. At this stage, I consider Click is still in the accumulation phase of external use-cases. So more unit tests the better! :) |
UNSET normalization
I agree, but the way I see it that's a change for 8.4 or 9.0 . There are too many different places which are independently responsible for choosing between For example, changes like this: class Option(Parameter):
_default: t.Any | UNSET
@property
def default(self):
if self._default is UNSET:
return None
return self._defaultBut I don't know how that looks across all usage sites. |
|
@sirosen I added the new section for you. In the future, you can just add a new section. If it is not there, it just means the maintainer who released forgot to add it after releasing. |
100% this. I could not find an way to do this cleanly in #3030 so I had to draw the line. Addressing this is indeed a refactor. In the mean time, your fix is in line with the policy we adopted:
So once you tweaked the code comments in the review I left you, this PR is to me good to be merged in a 8.3.1 hotfix release. |
When options are being parsed, multiple options may evaluate to have defaults of `UNSET`, and some may evaluate to have explicitly set defaults of `None`. The normalization of `UNSET -> None` is now deferred until all options have been parsed, so that it is possible to accurately evaluate and save the first non-UNSET default value. A new test exercises this functionality by pointing two flags at the same parameter declaration, and showing that their behavior is not order sensitive when only one of the flags has a default. resolves pallets#3071
Per review feedback: - Remove an extraneous comment - Expand another, more significant comment Co-authored-by: Kevin Deldycke <159718+kdeldycke@users.noreply.github.com>
ec9a4e9 to
189068a
Compare
|
I rebased and added the missing changelog note. I think this is ready! |
|
Good call @Rowlando13 on merging this! :) |
When options are being parsed, multiple options may evaluate to have defaults of
UNSET, and some may evaluate to have explicitly set defaults ofNone. The normalization ofUNSET -> Noneis now deferred until all options have been parsed, so that it is possible to accurately evaluate and save the first non-UNSET default value.A new test exercises this functionality by pointing two flags at the same parameter declaration, and showing that their behavior is not order sensitive when only one of the flags has a default.
resolves #3071
The PR template says to add a note in
CHANGES.rstfor the change, but there's no header for the next release, so I wasn't sure where to put a change note. If a maintainer gives me a pointer in terms of what to do, I'm happy to amend with a change note. 🙂