Summary
PYI034 correctly detects -> "ClassName" forward-reference strings for __iadd__ but misses them for __new__ and __enter__.
Reproduction
class Quoted:
def __new__(cls) -> "Quoted": ... # NOT caught (should be)
def __enter__(self) -> "Quoted": ... # NOT caught (should be)
def __iadd__(self, other) -> "Quoted": ... # Caught ✓
class Unquoted:
def __new__(cls) -> Unquoted: ... # Caught ✓
def __enter__(self) -> Unquoted: ... # Caught ✓
def __iadd__(self, other) -> Unquoted: ... # Caught ✓
Running ruff check --select=PYI034 produces:
PYI034 `__iadd__` methods in classes like `Quoted` usually return `self` at runtime
PYI034 `__new__` methods in classes like `Unquoted` usually return `self` at runtime
PYI034 `__enter__` methods in classes like `Unquoted` usually return `self` at runtime
PYI034 `__iadd__` methods in classes like `Unquoted` usually return `self` at runtime
| Method |
-> "Quoted" |
-> Unquoted |
__new__ |
❌ missed |
✅ caught |
__enter__ |
❌ missed |
✅ caught |
__iadd__ |
✅ caught |
✅ caught |
Expected behavior
All 6 methods should trigger PYI034, regardless of whether the return type uses a forward-reference string or direct reference.
Ruff version
Summary
PYI034 correctly detects
-> "ClassName"forward-reference strings for__iadd__but misses them for__new__and__enter__.Reproduction
Running
ruff check --select=PYI034produces:-> "Quoted"-> Unquoted__new____enter____iadd__Expected behavior
All 6 methods should trigger PYI034, regardless of whether the return type uses a forward-reference string or direct reference.
Ruff version