Revisiting variance

The pep says that it should be an intersection consisting of

Collection & MutabilityIsADistraction[int] or Collection & MutabilityIsADistraction[Permissions] , depending on which TypeIs from the example. pyright was the reference implementation and is not matching what the pep specifies, which might be an additional reason to pull the plug on this before release?

This should reduce to either MutabilityIsADistraction[int] or MutabilityIsADistraction[int & Any] or not reduce at all (same for permissions) if following the rule about set-theoretic intersections.

It’s also ignoring a direct cast:
image

So we don’t have a type checker that implements this correctly to even discuss why “correctly” is incorrect and you can work it out by hand if you want. This is following all the rules laid out by the PEP, and will result in the wrong type if you work out the rules of the pep by hand…

3 Likes