-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Bug: __class_getitem__ not recognised #14111
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
Comments
Duplicate of #11501 I believe. |
Yup. Thanks! |
I am not sure it is totally a duplicate. Did you see that if I don't have a parameters in my function mypy does not complain anymore ? def f(self):
self.__class__[str] This does not def f(self, field: str):
self.__class__[str] Why is the behavior changing ? |
The fundamental issue — that |
Oh, that's because your "function without parameters" is unannotated, meaning mypy just ignores it. It's a common footgun :) If you want mypy to check that function, add |
Oh I see ! Then yes it is a duplicate. Thanks for the clarification |
Bug Report
I am experienced a very weird behavior (which I am now pretty sure is a bug) with
__class_getitem__
.To Reproduce
Here I expect that mypy know that
__class__
is bounded by the class B and therefore implement__class_getitem__
.The weirdest part is that removing the parameter in
f
remove the problemExpected Behavior
mypy recognize that class can be indexed
Actual Behavior
mypy said it is no indexable even though B implement
__class_getitem__
Your Environment
Mypy version used: 0.990
Mypy command-line flags: None
Mypy configuration options from
mypy.ini
(and other config files): plugins = "pydantic.mypy"Python version used: 3.9
FYI: a more advance setup in this PR docarray/docarray#803
The text was updated successfully, but these errors were encountered: