-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Document typeshed better: a mypy upgrade suddenly triggers new errors due to typeshed changes #7735
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
The "correct" way to do this is to add a your own protocol and constrain class _SupportsSum(Protocol):
def __add__(self, __x: Any) -> Any: ...
V = TypeVar("V", bound=_SupportsSum) But we should probably add |
I'd prefer |
Is there any way to make this type of error more discoverable? I don't think most people would know to look at typeshed for this error. I wouldn't have known to use something from |
If anyone involved in typing is going to be at PyCon sprints, maybe some documentation for typeshed would be a good sprint task. |
The typing documentation is distributed over multiple sites, at the moment. There's also a lot of institutional knowledge that's onlyt written down in some issue discussions. https://typing.readthedocs.io is supposed to become a central documentation repository in the future, but there's nothing really there yet, unfortunately. |
There's actually a nice mypy PR I reviewed the other day that would improve the situation a little bit: The author doesn't seem to be particularly active at the moment, though, so idk if it has a chance of getting merged. And I agree with @srittau that it's much better to have this information in a centralised place rather than the mypy docs, and https://typing.readthedocs.io/ seems like the best place for this kind of thing. |
It would also be useful to distribute types like SupportsAdd in a .py package, maybe typing-extensions. |
It's been my plan for a long time now to get some of the definition from |
Something like this would also be helpful for guiding people to the likely source of the error in cases like this: |
sum
return type changed
I just updated MyPy in Jinja, and had to ignore the return type of
sum
in one of my functions because MyPy started saying it wasn't compatible with theTypeVar
I was using. pallets/jinja@a24df26I see a recent change related to the return type of
sum
: #7578. Is this a bug in typeshed/mypy, or is there a better way I should be annotating that function in Jinja?The text was updated successfully, but these errors were encountered: