◐ Shell
clean mode source ↗

parameter specification/type variable tuple variance by KotlinIsland · Pull Request #2215 · python/typing

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think using ... here is sound. Because it is both assignable-to and assignable-from any paramspec, it means that a case like the ContravariantParamSpec test will wrongly infer the paramspec as covariant (because lower is assignable to upper) before it even checks the contravariant direction.

I don't think there is any way to make the variance-inference algorithm described here correct and support inference of ParamSpec variance, without introducing the new concept of a "top signature".

(I'm also not sure how much value there is in including this particular variance-inference algorithm in the spec. I think it describes pyright's algorithm. I know that ty and pyrefly do not use this algorithm. I don't know about mypy or zuban.)