Skip to content

Add fallback-mode option for subset#1333

Open
takanabe wants to merge 2 commits into
v1from
20260611-backport-fallback-for-v1
Open

Add fallback-mode option for subset#1333
takanabe wants to merge 2 commits into
v1from
20260611-backport-fallback-for-v1

Conversation

@takanabe

@takanabe takanabe commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Backgroud

backport v2 merged code from #1308

Critical change

This PR also change subset arguments type hints from Optional[PercentageType] to Optional[float]

We had the type error: https://github.com/cloudbees-oss/smart-tests-cli/actions/runs/27386061774/job/80933216605

Run pipenv run type
launchable/commands/subset.py:621: error: Argument 1 to "float" has incompatible type "PercentageType"; expected "Union[SupportsFloat, SupportsIndex, str, Buffer]"  [arg-type]

Click's type system works like this:

  1. User runs: launchable subset --target 50%
  2. Click receives the raw string "50%"
  3. Click sees type=PERCENTAGE on the option, so it calls PercentageType.convert("50%", ...)
  4. convert() parses "50%" and returns 0.5
  5. Click passes 0.5 as target to subset()

PercentageType is called a "converter" because it converts the raw CLI string into a Python value. It's Click's extension point for custom argument types, which similar to how type=int makes Click convert "5" to 5. PercentageType does the same for percentages. The key point: convert() runs inside Click's internals, not in your code. Your function only ever sees the return value of convert(), which is a float. PercentageType itself never appears as a value anywhere in your code. This is why Optional[PercentageType] is misleading. It suggests the function receives a PercentageType instance, but it actually receives whatever convert() returned, which is float.

backport v2 merged code from #1308
@takanabe takanabe force-pushed the 20260611-backport-fallback-for-v1 branch from 02946a2 to e99a2c6 Compare June 12, 2026 00:20
Click's type system works like this:

1. User runs: launchable subset --target 50%
2. Click receives the raw string "50%"
3. Click sees type=PERCENTAGE on the option, so it calls PercentageType.convert("50%", ...)
4. convert() parses "50%" and returns 0.5
5. Click passes 0.5 as target to subset()

PercentageType is called a "converter" because it converts the raw CLI string into a Python value. It's Click's extension point for custom argument types, which similar to how type=int makes Click convert "5" to 5. PercentageType does the same for percentages. The key point: convert() runs inside Click's internals, not in your code. Your function only ever sees the return value of convert(), which is a float. PercentageType itself never appears as a value anywhere in your code. This is why Optional[PercentageType] is misleading. It suggests the function receives a PercentageType instance, but it actually receives whatever convert() returned, which is float.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant