Skip to content

Allow independent default values for empty min/max inputs - #233

Closed
Apeksha9389 wants to merge 2 commits into
maxfischer2781:masterfrom
Apeksha9389:fix/minmax-empty-default
Closed

Apeksha9389 wants to merge 2 commits into
maxfischer2781:masterfrom
Apeksha9389:fix/minmax-empty-default

Conversation

@Apeksha9389

@Apeksha9389 Apeksha9389 commented Oct 19, 2026 •

Copy link
Copy Markdown

Align empty-input min() and max() with Python's builtins by returning the supplied default without applying the key. This intentionally relaxes the previous internal signature, which tied the fallback to the key's input type.

The public overloads now infer the iterable's item type without a default and a union of the item and independent default types when a default is supplied. _min_max uses a separate default type variable. Documentation states that defaults are returned unchanged and may have a different type. Nonempty input still evaluates its keys, even if an actual item is identical to the fallback.

Runtime regressions cover sync/async input and sync/async keys. Type tests assert inference for keyed records with a None default, integer inputs with a string default, and calls without a default.

Validation on Python 3.12: all 412 runtime tests pass. Black, MyPy and PyRight pass. Flake8 passes on the source, runtime tests and changed type-test file. Running Flake8 over all type tests additionally reports pre-existing B019/B911 findings in unrelated files. Other interpreter versions are left to CI.

Prepared with AI assistance; reproduced and tested locally.

Closes #237

@Apeksha9389

Copy link
Copy Markdown
Author

Could a maintainer approve the pending CI runs and review this PR for merging? Local tests, Flake8, Black, MyPy, and PyRight all pass. Thank you.

@maxfischer2781

Copy link
Copy Markdown
Owner

Hi @Apeksha9389, please be aware that this package is maintained by humans. Going through 4 issues and 4 PRs takes time. Your posts and changes have been seen, there is no need to prod after just 2 hours.

@maxfischer2781

Copy link
Copy Markdown
Owner

Please see the comments on #237.

@maxfischer2781 maxfischer2781 self-assigned this Oct 19, 2026
@maxfischer2781

Copy link
Copy Markdown
Owner

So, do you want to make the change as noted in the ticket?

@Apeksha9389

Copy link
Copy Markdown
Author

Updated the definitions in d95e4e3. The public min/max overloads infer the item type without a default and the union of item/default types when a default is supplied. The internal _min_max now uses a separate type variable for the default instead of tying it to LT. The key still accepts only iterable items.

Added MyPy/PyRight assertions for keyed records with a None default, integer inputs with a string default, and calls without a default. Both type checkers pass, along with all 412 runtime tests, Black and Flake8 on the source, runtime tests and changed type-test file. The PR description now describes this as a behavior and typing change rather than a violation of the previous signature.

@Apeksha9389 Apeksha9389 changed the title Return empty min and max defaults without applying key Allow independent default values for empty min/max inputs Oct 20, 2026
@maxfischer2781

Copy link
Copy Markdown
Owner

See #230 (comment)

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.

[Bug]: min and max evaluate key on an empty-input default

2 participants