New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SupportsGetItem name confusing #11822
Comments
It's a bit weird that We should:
|
#11825 shows that there's only one place in the stdlib that actually meant to use the existing |
I'm getting the impression that most usages of the old |
|
Checking the third-party stubs, I only found one place where |
IMO stable shouldn't mean "will not receive bug fixes". I see this as a bug, not a feature. I would see it as a feature if many stubs relied on the current behavior. But to me, the meaning of stable/bug/feature doesn't really matter, and it's more about "practicality beats purity". |
Let's try this after |
I'm not sure if this is an issue with the type annotation for
itemgetter
orSupportsGetItem
.SupportsGetItem
requires defining__contains__
.typeshed/stdlib/_typeshed/__init__.pyi
Line 156 in 7ed91bc
This is surprising to me since I'd expect this trait to be about being able to index with
[n]
, which only should need__getitem__
. Perhaps there is a reason for it though, but then it meansitemgetter
can only be used with types that define__contains__
.typeshed/stdlib/_operator.pyi
Line 122 in 7ed91bc
This is despite
itemgetter
not usingin
or__contains__
, just indexing, so it should be allowed I thinkhttps://github.com/python/cpython/blob/main/Lib/operator.py#L288
One important effect is that while you'd expect
itemgetter
to always work instead of alambda x: x[0]
, it doesn't for these types.Deferred until
SupportsContainsAndGetItem
has made it into type checkers. Most likely after mypy 1.11.0 has been released.The text was updated successfully, but these errors were encountered: