Back to Ruff

Walrus operator

crates/ty_python_semantic/resources/mdtest/assignment/walrus.md

0.15.12227 B
Original Source

Walrus operator

Basic

py
x = (y := 1) + 1
reveal_type(x)  # revealed: Literal[2]
reveal_type(y)  # revealed: Literal[1]

Walrus self-addition

py
x = 0
(x := x + 1)
reveal_type(x)  # revealed: Literal[1]