[typing] Make arguments to __getitem__
/__setitem__
/ etc. positional only.
#125390
Labels
module: typing
Related to mypy type annotations
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
馃殌 The feature, motivation and pitch
A strict type checker will complain when overwriting
__getitem__
with a different argument:Gives:
Parameter 2 mismatch: base parameter "index" is keyword parameter, override parameter is position-only
when checking withpyright
.Note: most type-checkers support the white lie that if the parent class defines
__getitem__(self, index)
, then a subclass could do__getitem__(self, key)
, despite this not being type save. This could change in the future as more libraries adopt positional only parameters.Additional context
Such changes are backward-compatibility braking if a caller tries to execute something like
A.__getitem__(self=self, index=index)
.cc @ezyang @malfet @xuzhao9 @gramster
The text was updated successfully, but these errors were encountered: