Skip to content

Conversation

jorenham
Copy link
Member

@jorenham jorenham commented Jul 13, 2024

This changes the __dunder__ binary operator methods of the types in __init__.pyi to all have positional-only parameters.

The reason this is important, is because type-checkers consider e.g.

class CanAdd(Protocol):
    def __add__(self, x: Any) -> Any: ...

to be incompatible with

class CanAlsoAdd(Protocol):
    def __add__(self, y: Any) -> Any: ...

because the parameters x and y are allowed to be used as keyword argument, i.e. their names matter.

@seberg
Copy link
Member

seberg commented Jul 15, 2024

LGTM, and the explanation sounds logical so putting it in, thanks.

@seberg seberg merged commit 7ace427 into numpy:main Jul 15, 2024
@jorenham jorenham deleted the pos-only-binops branch July 15, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants