Skip to content

Document type auto-conversion and test set and frozenset - #3808

Merged
Rowlando13 merged 1 commit into
pallets:stablefrom
kdeldycke:test-frozenset-types
Sep 1, 2026
Merged

Document type auto-conversion and test set and frozenset#3808
Rowlando13 merged 1 commit into
pallets:stablefrom
kdeldycke:test-frozenset-types

Conversation

@kdeldycke

@kdeldycke kdeldycke commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

This is an ongoing exploration of usage of set and frozenset types in various places in the public API. It addresses the suspicion I had for a long time about inconsistent behavior, as detailed in #3036.

These tests for the moment only freeze the current behavior of Click. But reveals inconsistent or awkward behavior that are left to be discussed and decided upon for eventual bug fixes.

  1. A set, frozenset or dict default is guessed as a STRING, not a container type (test_type_from_default_container, test_convert_type_from_container_default). This contradicts the documented rule of "If no type is provided, the type of the default value is used" Should we change that so we guess a container type instead of the current STRING?

  2. An explicit type=set or type=frozenset is splitting the value provided to it (see test_explicit_container_type_splits_string). This looks like a bug we want to fix. My instinct is to split on commas, which overlaps an older discussion at: Allow nargs=-1 in options with a non-whitespace separator #2771 (comment) and my preference for it. Also dug out an old proposal at: Option value separators #422.

Also note that this also affects the envvars as demonstrated by my tests.

Closes #3036.

@kdeldycke
kdeldycke marked this pull request as draft August 29, 2026 10:30
@kdeldycke kdeldycke changed the title Test set and frozenset types in public API WIP: Test set and frozenset types in public API Aug 29, 2026
@kdeldycke kdeldycke added this to the 8.5.1 milestone Aug 29, 2026
@kdeldycke kdeldycke added typing Type annotations and stubs tests Click's own test suite and CI workflows labels Aug 29, 2026
@davidism

davidism commented Aug 29, 2026

Copy link
Copy Markdown
Member

For 1, it should probably read "If no type is provided, the type of the default value is used if it's recognized, otherwise STRING is used."

Or it might have been trying to describe the current behavior, and been a little vague. "If no type is provided, the type of the default is used directly, rather than applying a Click param type. This can lead to unexpected behavior when passing the string value to the type constructor, such as set."

@davidism

davidism commented Aug 29, 2026

Copy link
Copy Markdown
Member

For 2, I do not want to add comma splitting to the core behavior. It's maybe appropriate for a type, but not auto detected, and I'm not sure it needs to be in core at all. It's also very easy for users to misunderstand, if they type a, b suddenly it parses differently. The old PR you found seems like a different thing, it's about allowing --key:value instead of --key=value (also something I don't want to add, I agree with the closure.)

@kdeldycke
kdeldycke force-pushed the test-frozenset-types branch 2 times, most recently from f423c16 to 9b9596f Compare August 31, 2026 10:51
@kdeldycke

Copy link
Copy Markdown
Collaborator Author

Thanks @davidism for the feedback.

For point 1, I agree it is a documentation issue. Even your answer is not really clear. So instead of trying to generalize the paragraph, I went with an exhaustive list of values and how they're interpreted by Click. See my updated documentation in the PR.

For point 2, yes, I was pointing to the --key:value/--key=value case as a way to demonstrate how we consistently rejected value splitting and over-interpretation over the years. Be it comma-splitting or key-value splitting. So let's forget about splitting for now, this is another thing that can be revisited independently in the future.

So all in all, I propose to make this PR a documentation fix that is also freezing the current Click behavior with unittests. That way it can reach 8.5.1.

@kdeldycke
kdeldycke marked this pull request as ready for review August 31, 2026 11:04
@kdeldycke kdeldycke changed the title WIP: Test set and frozenset types in public API Test set and frozenset types in public API Aug 31, 2026
@kdeldycke kdeldycke changed the title Test set and frozenset types in public API Document type auto-conversion and test set and frozenset Aug 31, 2026
@kdeldycke
kdeldycke force-pushed the test-frozenset-types branch from 9b9596f to 1864be1 Compare August 31, 2026 11:15
@davidism

Copy link
Copy Markdown
Member

I like the docs, and agree with adding tests to cover this behavior.

@Rowlando13

Copy link
Copy Markdown
Member

This looks good. Are you ready for me to merge?

@kdeldycke
kdeldycke force-pushed the test-frozenset-types branch from 1864be1 to 394088a Compare September 1, 2026 06:49
@kdeldycke

Copy link
Copy Markdown
Collaborator Author

This looks good. Are you ready for me to merge?

Yes! I don't like the result of these coverage, but at least it plugs documentation holes and lockdown the current behavior of Click. So this is a net benefits for the project. Let's keep the debate for another day! :)

@kdeldycke kdeldycke added the docs Updates to documentation, readme, docstrings, typos label Sep 1, 2026
@Rowlando13
Rowlando13 merged commit e5cb12b into pallets:stable Sep 1, 2026
12 checks passed
@kdeldycke
kdeldycke deleted the test-frozenset-types branch September 1, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Updates to documentation, readme, docstrings, typos tests Click's own test suite and CI workflows typing Type annotations and stubs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants