-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
min/max are missing optional default keyword only argument #77
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Aha! The fix for this was waiting for a change in mypy. That change has now landed (python/mypy#1150) so we can now accept a PR to add this. |
I don't really know the |
Looks like you need to add `key: Callable[[_T], Any] = None` to line 661.
|
I raised this issue about the |
Oh, sorry. You're right.
|
I experienced mix/max issues with the following code: from typing import Optional
class MyObject:
def __init__(self, attribute: int) -> None:
self.attribute = attribute
def find_biggest_attribute(objects: list[MyObject]) -> Optional[MyObject]:
return max(objects, default=None, key=lambda object: object.attribute)
print(find_biggest_attribute([MyObject(42), MyObject(41)]))
print(find_biggest_attribute([])) Running mypy_bug.py:10: error: Item "None" of "Optional[MyObject]" has no attribute "attribute" [union-attr]
return max(objects, default=None, key=lambda object: object.attribute)
^~~~~~~~~~~~~~~~
Found 1 error in 1 file (checked 1 source file) As per Python built-in max() documentation:
|
Please do not post on unrelated ancient issues. What you experience is a problem with mypy, not typeshed. It's probably the same as python/mypy#14664. |
In py3, the min and max argument take an optional keyword only argument,
default
, but this isn't in the type signature stub.https://github.com/python/typeshed/blob/master/stdlib/3/builtins.pyi#L660-L663
The text was updated successfully, but these errors were encountered: