Repository navigation
Python: require ty-types 1.0.3 - #10320
Merged
Merged
Conversation
ty-types 1.0.2 gave an assignment expression in a comprehension a symbol
in the comprehension's scope, so one variable split into two symbols and
two Variables:
total = 0
sums = [total := total + v for v in values]
return total
total = 0 and the read inside the comprehension had one symbol, the
target and return total another. 1.0.3 (openrewrite/ty-types#40) binds
the target in the scope around the comprehension, where Python binds it.
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.
With ty-types 1.0.2, one variable assigned through
:=in a comprehension became twoJavaType.Variables, so a recipe saw two variables where Python has one:ty-types put the target's symbol in the comprehension's scope. Python binds it in the scope around the comprehension (PEP 572), and the reads after the comprehension resolved to that misplaced symbol. Since #10313, Variables are shared per ty symbol, so the split surfaced as two Variables.
ty-types 1.0.3 (openrewrite/ty-types#40) binds the target in the enclosing scope, so all four references name one symbol. This PR requires 1.0.3. The new test in
test_type_interning.pychecks that the fourtotalreferences share one Variable. It fails with 1.0.2 and passes with 1.0.3.It also drops the sentence in
_variable_owner's docstring (#10318) that described the 1.0.2 behavior. The code it explained stays: a lambda or comprehension never owns a variable, so the path is matched only up to the scope that does.