Files
ruff/crates/red_knot_python_semantic/resources/mdtest/assignment/augmented.md

470 B

Augmented assignment

Basic

x = 3
x -= 1
reveal_type(x)  # revealed: Literal[2]

Dunder methods

class C:
    def __isub__(self, other: int) -> str:
        return "Hello, world!"

x = C()
x -= 1
reveal_type(x)  # revealed: str

Unsupported types

class C:
    def __isub__(self, other: str) -> int:
        return 42

x = C()
x -= 1

# TODO: should error, once operand type check is implemented
reveal_type(x)  # revealed: int