Skip to content

Reorder ParameterSource #2879

Description

@madduck

Please consider sorting ParameterSource in order of "explicitness", as this
would make it easier to test for how explicit a parameter is.

Currently, the values are:

  1. COMMANDLINE
  2. ENVIRONMENT
  3. DEFAULT
  4. DEFAULT_MAP
  5. PROMPT

If I want to test whether a parameter has been explicitly provided, I need to
test whether that is not DEFAULT and not DEFAULT_MAP.

Consider this order instead:

  1. PROMPT
  2. COMMANDLINE
  3. ENVIRONMENT
  4. DEFAULT_MAP
  5. DEFAULT

Now I can test x < DEFAULT_MAP. And if #2878 goes anywhere, CONFIGFILE could be slotted in before DEFAULT_MAP.

Activity

  1. kdeldycke commented on Mar 5, 2026

    @kdeldycke
    Collaborator

    I like the idea of having that natural order. Not necessarily to simplify the precedence code (although it might be a nice touch), but so the precedence policy of Click is diffused in the code itself.

    As for extending this enum with CONFIGFILE I was thinking of doing the same for a long time in my own Click Extra project. But nowadays I think DEFAULT_MAP is good enough and that's the way to go: have configuration files setting their values to DEFAULT_MAP.

    That's exactly what I am doing with Click Extra: https://github.com/kdeldycke/click-extra/blob/96719fdcd7916acb03ac2e13f0885aeb0c07d76c/click_extra/config.py#L1100-L1128

  2. self-assigned this
    on Mar 5, 2026
  3. added a commit that references this issue on Mar 5, 2026
    93217f1
  4. kdeldycke commented on Mar 5, 2026

    @kdeldycke
    Collaborator

    @madduck I explored your idea in this PR: #3248 . Can you check it?

  5. added a commit that references this issue on Mar 5, 2026
    1f42ba5
  6. added 4 commits that reference this issue on Apr 8, 2026
    d7d41bb
    d44d711
    4d0a4dd
    ac5cec5
  7. added this to the 8.3.3 milestone on Apr 16, 2026
  8. kdeldycke commented on Apr 16, 2026

    @kdeldycke
    Collaborator

    A fix has been pushed to stable and will be part of the 8.3.3 release.

  9. linked a pull request that will close this issueReorder `ParameterSource` #3248on Apr 16, 2026
  10. locked as resolved and limited conversation to collaborators on May 1, 2026
  11. added
    parsingParsing, parameters, commands, chaining, context
    and removed on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docsUpdates to documentation, readme, docstrings, typosparsingParsing, parameters, commands, chaining, context

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions