-
Notifications
You must be signed in to change notification settings - Fork 122
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
chore: upgrade pyright to 1.1.385 #1438
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, much simpler than previous Pyright upgrades! Maybe Python types are stabilising after all.
@@ -1359,7 +1359,7 @@ def _request( | |||
raise resp | |||
if callable(resp): | |||
resp = resp() | |||
return resp | |||
return resp # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know why the ignore is needed now? Can we do anything else to avoid it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had done some testings before ignoring this, and I think it's because the self.responses
is typing.List[typing.Any]
.
If a response is an exception, it's raised. If it's a callable, it's called and the returned type is an object. If none of those cases are matched, it's returned.
So the returned result type is object | Any
, which doesn't match the method's return type typing.Dict[str, typing.Any]
.
Casting the final return would help, like return typing.cast(typing.Dict[str, typing.Any], resp)
. I ignored it because I think it's simpler, since the return type is already annotated with this type.
I'm merging now with the ignore, if the type casting is preferred, I can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so probably the best thing would be to tighten up the annotation for responses
(or not overload it as much) to avoid needing the ignore or a cast. I guess the newer pyright found this but the older one didn't for some reason.
Leaving this for another day seems fine - I don't think it's worth opening an issue or PR now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's in a test file so I don't think worth spending more time on now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When in doubt, do this:
from typing import reveal_type
reveal_type(resp)
I've poked around for a couple of minutes and discovered that:
- if resp is callable, that callable always raises, and the line above is misleading
- it's trivial to set the correct type, (below) and even our lambdas are auto-detcted when because they call functions that raise uconditionally
self.responses: list[Callable[[], NoReturn]|dict[str, Any]|Exception] = []
(code above assumes from __future__ import annotations
and from typing import ...
)
Its ominous that one of the two features landed for 3.14 is type related though 😂. |
Upgrade pyright version to the latest (1.1.385).