Skip to content

Streamline option flag management#3641

Open
kdeldycke wants to merge 1 commit into
pallets:mainfrom
kdeldycke:option-flag-management-refactor
Open

Streamline option flag management#3641
kdeldycke wants to merge 1 commit into
pallets:mainfrom
kdeldycke:option-flag-management-refactor

Conversation

@kdeldycke

Copy link
Copy Markdown
Collaborator

This refactor is an attempt in streamlining the code around flag management in Option.

I hope this is not too big to digest. I did not went too far and just focused on Option internals and flag-management. My goal is to colocate decision code by domain. Like having all prompt-related code in the same block. Or all type-resolution code together. Sometimes in the same code block, sometimes under a private utility function. My heuristic is mostly driven by the number of lines and the content of the docstring.

Another idiom I introduced was using @property for is_bool_flag. I didn't see that much propoerties used in Click, but these are easier to reason about for me.

I also used the oportunity to introduce a type inference point in _pick_type which is a small step echoing what @sirosen was proposing last year about having a separation between "data which is stored (where you might have UNSET) from the data which is viewed". That also resurface the infamous UNSET a bit, but hidden into a new flag_activation_value property. And _hide_unset is a way to delimit the internals state from the presetation state.

This also contains some small syntax cleanups that were flagged by my linters.

Proof that this is the right time to introduce this refactor: after accumulating a lot of unitetsts over the past few years, I did not break any. And I did not discovered any new blind spot in the test suite.

I hope this will make code easier to read and maintain. But I need other eyes to check that.

My initial goal was way too ambitious as I want to create a FlagOption subclass of Option. But this is way too big and not sure I can pull it yet. So this is like a first step in that general direction.

@kdeldycke kdeldycke added this to the 8.5.0 milestone Jun 27, 2026
@kdeldycke kdeldycke added the f:parameters feature: input parameter types label Jun 27, 2026
@kdeldycke kdeldycke force-pushed the option-flag-management-refactor branch from 9ca44ec to 3a9316a Compare June 27, 2026 08:07
@kdeldycke kdeldycke force-pushed the option-flag-management-refactor branch from 3a9316a to 3b743b8 Compare June 27, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f:parameters feature: input parameter types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant