Skip to content

Python: require ty-types 1.0.3 - #10320

Merged
knutwannheden merged 1 commit into
mainfrom
python-require-ty-types-1.0.3
Dec 4, 2026
Merged

knutwannheden merged 1 commit into
mainfrom
python-require-ty-types-1.0.3

Conversation

@knutwannheden

Copy link
Copy Markdown
Contributor

With ty-types 1.0.2, one variable assigned through := in a comprehension became two JavaType.Variables, so a recipe saw two variables where Python has one:

def partial(values: list[int]):
    total = 0                                    # symbol A
    sums = [total := total + v for v in values]  # read: A, target: B
    return total, sums                           # B

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.py checks that the four total references 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.

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.
@knutwannheden knutwannheden self-assigned this Dec 4, 2026
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Dec 4, 2026
@knutwannheden
knutwannheden merged commit 28f4673 into main Dec 4, 2026
1 check passed
@knutwannheden
knutwannheden deleted the python-require-ty-types-1.0.3 branch December 4, 2026 09:03
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant