Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Improve usage of outer context for inference #5699
This PR fixes a problems when mypy commits to soon to using outer context for type inference. This is done by:
In general, instead of adding a special case, it would be better to use inner and outer context at the same time, but this a big change (see comment in code), and using the simple special case fixes majority of issues. Among reported issues, only #5311 will stay unfixed.
I'm not sure if I have enough context on how we handle generics to say for certain whether or not this approach is the best one/give more global feedback, but FWIW these changes all look pretty reasonable to me.
I did have a few questions, but they're mostly about the old existing code that you were copying over -- I only had a few nitpicks for the actual changes you're making.
Glad to see so many issues fixed! This looks reasonable, just left some minor comments.
Random idea: If type variable with a bound is used in an invariant context and we can't infer a value, we currently infer
C[<nothing>]. What if we'd instead inferred
C[<bound>]? This would generate better error messages. Alternatively, maybe we should generate an error right away.