-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
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
ruff 0.9.4
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule