Add augmented assignment inference for -= operator (#13981)

## Summary

See: https://github.com/astral-sh/ruff/issues/12699
This commit is contained in:
Charlie Marsh 2024-10-29 22:14:27 -04:00 committed by GitHub
parent 39cf46ecd6
commit c6b82151dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 179 additions and 65 deletions

View file

@ -0,0 +1,35 @@
# Augmented assignment
## Basic
```py
x = 3
x -= 1
reveal_type(x) # revealed: Literal[2]
```
## Dunder methods
```py
class C:
def __isub__(self, other: int) -> str:
return "Hello, world!"
x = C()
x -= 1
reveal_type(x) # revealed: str
```
## Unsupported types
```py
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
```