Skip to content

Fully define min and max - #328

Open
lgalfaso wants to merge 2 commits into
bazelbuild:masterfrom
lgalfaso:patch-8
Open

Fully define min and max#328
lgalfaso wants to merge 2 commits into
bazelbuild:masterfrom
lgalfaso:patch-8

Conversation

@lgalfaso

@lgalfaso lgalfaso commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

The definition of min and max was not taking into account the case that they were called with multiple positional arguments.

When called with one positional argument, clarify that the element must be iterable.

This extended definition is consistent with the current implementation of Bazel and with Python.

The definition of `min` and `max` was not taking into account the case that they were called with multiple positional arguments.

When called with one positional argument, clarify that the element must be iterable.

This extended definition is consistent with the current implementation of Bazel and with Python.
@lgalfaso
lgalfaso requested a review from brandjon as a code owner December 6, 2025 14:38
@albertocavalcante

Copy link
Copy Markdown

@brandjon @tetromino can you please take a look? Thanks!

@tetromino tetromino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch that for min/max it's sufficient for the first argument to be an iterable, not necessarily a collection!

I would suggest changing the doc to make the method's signature clearer in the two cases. Maybe something like this:


max returns the greatest element.

When called with one positional argument, max(x, key=None) returns the greatest element in the iterable value x. It is an error if x is empty, not iterable, or if any of its elements do not support ordered comparison with others.

When called with 2 or more positional arguments, max(key=None, *args) returns the greatest of its positional args. It is an error if any of the positional arguments do not support ordered comparison with others.

It is an error to call max with no positional arguments.

Outline the case that there is only one parameter.
@lgalfaso

Copy link
Copy Markdown
Contributor Author

Updated the PR with the recommended wording.

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.

3 participants