Replies: 1 comment
-
|
If you're maintaining a library, I recommend against relying on old-style TypeVar behaviors and manually overriding variance in a way that makes these classes no longer type safe. If this is for your own internal code base, then the stakes are much lower, and this might be an acceptable risk to take. The best solution here is for the type community to converge on a solution that all type checkers implement. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As discussed in various places e.g. https://discuss.python.org/t/make-replace-stop-interfering-with-variance-inference/96092/42, the changes in python 3.13 make frozen generic dataclasses invariant, not covariant. For mypy, there is no way around it, but pyright allows to use old-style type vars with covariant=True and treat these classes as covariant. Currently this escape hatch allows the user to decide on the trade-off between usability and soundness. Would choosing to use this be a future-proof solution or is there a risk of this behavior changing in the future? I want to assess the risk of updating to 3.13 and later having to pin the pyright version to avoid breaking.
Beta Was this translation helpful? Give feedback.
All reactions