typing: improve applicator overloads - #333
Conversation
Represent existing formatter applicator behavior more precisely for sequence inputs, conditional formatting, and curried call forms.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b848e358b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| formatter_condition_pairs: Sequence[ | ||
| tuple[Callable[[TArgument], bool], Callable[[TArgument], TReturn]] | ||
| ], |
There was a problem hiding this comment.
Preserve per-branch formatter input types
When branches use TypeGuards for different alternatives—such as an object -> TypeGuard[str] condition paired with a str -> str formatter and an object -> TypeGuard[int] condition paired with an int -> int formatter—this shared TArgument requires every formatter to accept the original object. Mypy therefore rejects this type-safe and natural use of apply_one_of_formatters; the same constraint is duplicated in the curried overloads. Model each condition/formatter pair's narrowed input independently so heterogeneous guarded branches remain usable.
Useful? React with 👍 / 👎.
Improve formatter applicator annotations to match existing sequence-compatible runtime behavior.
What was wrong?
Some applicator annotations were list-only or too broad, even though runtime behavior already supports tuple/sequence inputs and curried call forms.
Related to Issue #
Closes #
How was it fixed?
Tightened generic annotations and overloads for formatter applicators and curried helpers, including TypeGuard-aware conditional formatting. Runtime logic is unchanged, with mypy coverage for the updated typing.
Todo:
Cute Animal Picture