Skip to content

typing: improve applicator overloads - #333

Draft
BobTheBuidler wants to merge 1 commit into
ethereum:mainfrom
BobTheBuidler:type-hints/applicator-overloads
Draft

typing: improve applicator overloads#333
BobTheBuidler wants to merge 1 commit into
ethereum:mainfrom
BobTheBuidler:type-hints/applicator-overloads

Conversation

@BobTheBuidler

@BobTheBuidler BobTheBuidler commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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

Cute puppy

Represent existing formatter applicator behavior more precisely for sequence inputs, conditional formatting, and curried call forms.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread eth_utils/applicators.py
Comment on lines +166 to +168
formatter_condition_pairs: Sequence[
tuple[Callable[[TArgument], bool], Callable[[TArgument], TReturn]]
],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@BobTheBuidler
BobTheBuidler marked this pull request as draft July 29, 2026 10:26
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.

2 participants