Skip to content

Reconcile default value passing and default activation#3239

Open
kdeldycke wants to merge 1 commit intopallets:stablefrom
kdeldycke:fix-bool-flag-default-true
Open

Reconcile default value passing and default activation#3239
kdeldycke wants to merge 1 commit intopallets:stablefrom
kdeldycke:fix-bool-flag-default-true

Conversation

@kdeldycke
Copy link
Copy Markdown
Collaborator

@kdeldycke kdeldycke commented Mar 2, 2026

This is an attempt to address #3111, and explore the consequences of reconciling the two meaning of the default parameter:

  1. "Pass this Python value to my function if the flag isn't used", i.e. when default=True then function gets True
  2. "Activate this flag by default", i.e. when default=True then function gets flag_value

A way to do that would be to consider default=True as a sentinel (yes, you can call me the sentinel-guy), for non-boolean flags. We do it lazily in the get_default method to not interfere with class instanciation, which we implemented in #3225 to fix #3121.

This has the side-effect of refining the test cases introduced in 06847da for #3030.

@kdeldycke kdeldycke added this to the 8.3.2 milestone Mar 2, 2026
@kdeldycke kdeldycke marked this pull request as draft March 2, 2026 07:54
@kdeldycke kdeldycke changed the title Reconcile default value passing and default activation WIP: Reconcile default value passing and default activation Mar 2, 2026
@kdeldycke kdeldycke added bug f:parameters feature: input parameter types labels Mar 2, 2026
@kdeldycke kdeldycke force-pushed the fix-bool-flag-default-true branch from a61dcee to 22351f8 Compare March 2, 2026 08:00
@kdeldycke kdeldycke force-pushed the fix-bool-flag-default-true branch from 22351f8 to 41ed4bc Compare March 2, 2026 09:10
@kdeldycke kdeldycke marked this pull request as ready for review March 2, 2026 09:13
@kdeldycke
Copy link
Copy Markdown
Collaborator Author

Ah sorry I fuck-up jungling with all these PRs to rebase. This commit 6c4a77b shouldn't have been pushed to stable. It should have been part of this PR. I'll revert the changes.

@kdeldycke
Copy link
Copy Markdown
Collaborator Author

Ok, juste revert stable as it was via: bb7be1f

@kdeldycke kdeldycke force-pushed the fix-bool-flag-default-true branch 2 times, most recently from 1296a4c to 4af30ca Compare March 2, 2026 09:21
@kdeldycke kdeldycke changed the title WIP: Reconcile default value passing and default activation Reconcile default value passing and default activation Mar 2, 2026
@Rowlando13 Rowlando13 modified the milestones: 8.3.2, 8.3.3 Mar 15, 2026
@kdeldycke kdeldycke force-pushed the fix-bool-flag-default-true branch 5 times, most recently from d5a6a46 to 30aca6b Compare April 8, 2026 15:27
Fix pallets#3111
Reintroduce a commit pushed by mistake in 6c4a77b and reverted in bb7be1f
Refine tests introduced in 06847da for pallets#3030
Document the interaction between `default` and `flag_value`
@kdeldycke kdeldycke force-pushed the fix-bool-flag-default-true branch from 30aca6b to d34f72b Compare April 9, 2026 13:13
The `default` value is given to the underlying function as-is. So if you set `default=None`, the function receives `None`. Same for any other type.

Which means, in example above, this option:
But there is a special case for **non-boolean** flags: if a flag has a non-boolean `flag_value` (like a string or a class), then `default=True` is interpreted as *the flag should be activated by default*. The function receives the `flag_value`, not the Python `True`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap docs at 80 characters.

.. versionchanged:: 8.3.3
``default=True`` is no longer substituted with ``flag_value`` for
boolean flags, fixing negative boolean flags like ``flag_value=False,
default=True``. :issue:`3111`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not link to issues or PRs in docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug f:parameters feature: input parameter types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants