Replies: 1 comment 1 reply
-
Pyright does a limited form of this in match statements, as you see above. To my knowledge, no other type checker does even that. In general, entanglements between variables is problematic for performance reasons. It creates dependencies (often false dependencies) that greatly increase the time it takes for type evaluations to converge. This can cause analysis times for a function (especially one that has a loop) to increase a hundredfold. I was able to mitigate this performance impact in the case of a I think example 2 would be possible to implement without a significant performance hit, but it would be quite a bit of work to implement. It's something I'd consider adding in the future — but only if there's a strong signal from pyright users that it's a common pattern. |
Beta Was this translation helpful? Give feedback.
-
I've noticed that Pyright doesn't narrow the type of a value based on the type of values "connected" to it.
In the following examples, Pyright could theoretically narrow the types further by noticing the types of the tuple elements are correlated/entangled.
I would love to see this added!
Examples rely on the following function
Example 1
Pyright doesn't infer that
b
's type can only beint
, despitea
being narrowed tostr
which impliesb
must be typeint
.Example 2
Pyright says
foo
's type can betuple[int, None]
despite the previous check proving the first element can't beint
.Example 3
Interestingly this works.
Beta Was this translation helpful? Give feedback.
All reactions