Skip to content

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

Closed

Description

@Apeksha9389

What happened?

Expected None without evaluating the key, matching Python min. Actual output is TypeError. max has the same problem.

Reproduced on master 0605c7b, asyncstdlib 3.14.0, Python 3.12.14. A tested fix is available in #233.

Minimal Reproducible Example

import asyncio
import asyncstdlib as a

async def example():
    print(await a.min([], key=lambda row: row["priority"], default=None))

asyncio.run(example())

Request Assignment

Prepared with AI assistance; reproduced locally.

Activity

  1. maxfischer2781 commented on Oct 19, 2026

    @maxfischer2781
    Owner

    As per the signature, this is not a bug. default: T must be compatible with the key: (T) -> bool. In your example, None is not a valid input for ({"priority": T'}) -> T'.

    I do grant that the behaviour is a) not consistent with builtin max/min and b) needlessly restrictive. If you want to make the behaviour change, please adjust the function definitions accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions