Skip to content

Conversation

@sterliakov
Copy link
Collaborator

Fixes #19185. Fixes #19186.

Replaces #19382 (not closing that yet, need to extract another part related to applytype from there to another PR).

When a TypeVar defaults to another TypeVar, that default should already be in scope. Fortunately we already analyze them in the correct order, so the active scope has all the necessary information. This fixes the namespace drift problem because the bound typevars are already adjusted to use the correct namespace, and we do not need to touch their global definitions.

I am not super happy about making TypeVarLikeScope impure here - any suggestions? Would passing self.msg to every bind_new call look saner?

@github-actions

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

re pureness: maybe we can pass msg into bind_new and have the TypeVarLikeDefaultFixer store messages that we report in bind_new?

edit: oops, didn't see you suggested that. yeah i think that might be nicer!

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@sterliakov
Copy link
Collaborator Author

@hauntsaninja yeah, this looks better indeed. Unfortunately I can't pass msg directly (it is not available in typeanal, and I don't want to extend SemanticAnalyzerCoreInterface further), so I settled on passing fail_func alone.

I don't think collecting all messages and returning them to the caller would be better - we call bind_new in multiple places, and each one would need to handle those separately. Passing a "report" function provides sufficient separation IMO.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants