mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 14:52:01 +00:00

Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
## 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`
33 lines
645 B
Markdown
33 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
|
|
```
|