[ty] Report redefined legacy TypeVars#25854
Merged
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.36%. The percentage of expected errors that received a diagnostic held steady at 88.82%. The number of fully passing files held steady at 93/134. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-legacy-type-variable |
1 | 0 | 0 |
| Total | 1 | 0 | 0 |
Raw diff:
setuptools (https://github.com/pypa/setuptools)
+ setuptools/_vendor/jaraco/functools/__init__.py:677:1 error[invalid-legacy-type-variable] Cannot redefine `_T` as a type variable65778d4 to
7234735
Compare
7234735 to
95f0739
Compare
dcreager
reviewed
Jun 11, 2026
3ecad3d to
c43d712
Compare
c43d712 to
05b9c29
Compare
Member
Author
dcreager
approved these changes
Jun 12, 2026
charliermarsh
added a commit
that referenced
this pull request
Jun 12, 2026
## Summary
An mdtest section is evaluated as a single Python module, even when its
examples are split across multiple fenced code blocks. Some existing
sections therefore define the same legacy `TypeVar` name more than once:
```python
T = TypeVar("T")
# ...
T = TypeVar("T")
```
#25854 will correctly diagnose the second definition, but these
duplicates are incidental to the tests. This separates self-contained
examples into distinct mdtest sections and gives the remaining type
variables distinct names where the examples depend on shared setup. The
expected types and diagnostics are unchanged.
This is the preparatory base for #25854 and doesn't change behavior.
Base automatically changed from
charlie/avoid-typevar-redefinitions-in-mdtests
to
main
June 12, 2026 01:52
05b9c29 to
59a62d9
Compare
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.
Summary
The
invalid-legacy-type-variablerule already validates the assignment shape and declared name, but it did not report when a name had already been defined in the same scope:The diagnostic points back to the preceding definition and considers earlier bindings and declarations that are reachable from the beginning of the owning scope.
The implementation reuses the existing per-place use-def snapshot and reachability predicates, so it only inspects definitions of the target name rather than scanning every definition in the scope.
Closes astral-sh/ty#3732.