Skip to content

Return empty min and max defaults without applying key - #233

Open
Apeksha9389 wants to merge 1 commit into
maxfischer2781:masterfrom
Apeksha9389:fix/minmax-empty-default
Open

Apeksha9389 wants to merge 1 commit into
maxfischer2781:masterfrom
Apeksha9389:fix/minmax-empty-default

Conversation

@Apeksha9389

@Apeksha9389 Apeksha9389 commented Oct 19, 2026 •

Copy link
Copy Markdown

This PR fixes min() and max() applying their key function to the fallback value of an empty iterable. For example, await min([], key=lambda record: record["priority"], default=None) raises TypeError instead of returning None. Defaults need not have the same shape as input records.

Handle initial iterator exhaustion before evaluating a key. Return the provided default unchanged, and retain the existing ValueError when there is no default. Nonempty input still evaluates keys even if its first item is identical to the default.

Eight new regressions fail on master and pass here, covering min/max, sync/async inputs and sync/async keys. Two positive controls distinguish empty input from an actual item identical to the fallback. This is independent of the tie-selection fix in #231, which leaves the empty-input path unchanged.

Validation on Python 3.12: 412 tests pass. Repository-wide Flake8, Black, MyPy and PyRight pass. 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
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