Repository navigation
Fix new style union aliases with not ready items - #22172
Open
ilevkivskyi wants to merge 1 commit into
Open
ilevkivskyi wants to merge 1 commit into
ilevkivskyi wants to merge 1 commit into
Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/settings/context.py:29: error: Variable "prefect.settings.context.SettingKey" is not valid as a type [valid-type]
- src/prefect/settings/context.py:29: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/prefect/settings/context.py:30: error: Variable "prefect.settings.context.SettingKey" is not valid as a type [valid-type]
- src/prefect/settings/context.py:30: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/prefect/settings/context.py:31: error: Variable "prefect.settings.context.SettingKey" is not valid as a type [valid-type]
- src/prefect/settings/context.py:31: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21263
Fixes #11887
Old style aliases with new style unions are quite tricky, since this requires some heuristics to figure out whether this is a type alias or a regular variable. Things get even trickier when some items are not ready, because our heuristics must be robust w.r.t. to this.
I spent few hours today playing with this, and I don't think there is a fully-principled fix that doesn't involve rewriting a bunch of logic. But I think I have something that is still fairly principled. Namely, in this PR:
becomes_typeinfostatus for imported placeholders consistently.should_wait_rhs()back in sync withcan_be_type_alias()w.r.t.OpExpr.Note, the root cause of the crash is that we normally never change a type alias back to a regular variable. Normal flow for a symbol table entry is always like this
None -> PlaceholderNode -> PlaceholderNode(becomes_typeinfo=True) -> SymbolNode(where some steps may be skipped). A lot of logic depends on this, but in the relevant scenarios it is tricky to follow this principle.cc @JukkaL