[ty] Preserve recursively-defined flag during normalization#24276
Open
charliermarsh wants to merge 1 commit intomainfrom
Open
[ty] Preserve recursively-defined flag during normalization#24276charliermarsh wants to merge 1 commit intomainfrom
charliermarsh wants to merge 1 commit intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 86.60%. The percentage of expected errors that received a diagnostic held steady at 81.47%. The number of fully passing files held steady at 69/132. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
|
AlexWaygood
reviewed
Mar 29, 2026
Member
AlexWaygood
left a comment
There was a problem hiding this comment.
Can we add a regression test for this?
53d50ff to
6a18c97
Compare
Member
Author
|
Added, sorry. (This was present in https://github.com/astral-sh/ruff/pull/24272/changes#diff-19ac4a4d9337821d0bbfb544ab4e3fda87df59c6ea06065b77d3fcf5cf682ec2R2809 but forgot to carry it over.) |
6a18c97 to
0d7584e
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
This PR allows the
Unknownvariant to retain a recursively-normalized flag so that it's not dropped during normalization.Consider this motivating example:
PositiveCount.iis initially inferred asUnknownin the subclass (the subclass doesn't seeself.i = 0upfront, becauseimplicit_attribute_inneroperates on a single class). Instead, it sees theself.i = self.i + 1andself.i = self.i - 1statements, which addsDivergentto the type. Recursive normalization drops theDivergentarms and marks the result recursive... but that flag doesn't have anywhere to go. Then, when evaluatingself.i + 1, it walks the MRO and adds theLiteral[0]fromself.i = 0, so we haveUnknown | Literal[0], but we've already "lost" the recursively-normalized flag.I also considered #24272 which is more targeted, but this felt more structurally correct and less targeted.
Closes astral-sh/ty#3149.