ruff
67d8c544 - [ty] Retain recursively-defined state in binary expressions (#25277)

Commit
8 days ago
[ty] Retain recursively-defined state in binary expressions (#25277) ## Summary Prior to this change, a recursive implicit attribute like: ```python from __future__ import annotations from typing import Final class ScopeChain: def __init__(self, parent: ScopeChain | None = None) -> None: self.depth: Final = 1 if parent is None else parent.depth + 1 ``` ...could fail to converge during type inference. We now preserve the recursive-definition marker when literal binary operations produce a new literal result, so recursive literal unions continue through the existing widening path instead of accumulating results indefinitely. Note: in the above snippet, the bare `Final` exposes the issue because we infer the RHS to get the type, as opposed to relying on the annotation, but in theory it needn't be specific to `Final`... Codex believes this is the only way to trigger that panic as of now, though because it's the only site where we create a recursive attribute lookup _and_ retain the exact RHS literal type (e.g., the non-`Final` version, `self.depth = 1 if parent is None else parent.depth + 1`, promotes those literals). Closes https://github.com/astral-sh/ty/issues/3499.
Author
Parents
Loading