mirror of
https://github.com/astral-sh/ruff
synced 2026-01-07 22:54:28 -05:00
## Summary This PR adds cycle handling for `infer_unpack_types` based on the analysis in astral-sh/ty#364. Fixes: astral-sh/ty#364 ## Test Plan Add a cycle handling test for unpacking in `cycle.md`
34 lines
645 B
Markdown
34 lines
645 B
Markdown
# Cycles
|
|
|
|
## Function signature
|
|
|
|
Deferred annotations can result in cycles in resolving a function signature:
|
|
|
|
```py
|
|
from __future__ import annotations
|
|
|
|
# error: [invalid-type-form]
|
|
def f(x: f):
|
|
pass
|
|
|
|
reveal_type(f) # revealed: def f(x: Unknown) -> Unknown
|
|
```
|
|
|
|
## Unpacking
|
|
|
|
See: <https://github.com/astral-sh/ty/issues/364>
|
|
|
|
```py
|
|
class Point:
|
|
def __init__(self, x: int = 0, y: int = 0) -> None:
|
|
self.x = x
|
|
self.y = y
|
|
|
|
def replace_with(self, other: "Point") -> None:
|
|
self.x, self.y = other.x, other.y
|
|
|
|
p = Point()
|
|
reveal_type(p.x) # revealed: Unknown | int
|
|
reveal_type(p.y) # revealed: Unknown | int
|
|
```
|