-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#22778Milestone
Description
Summary
If a member variable with an explicit type hint is assigned to in a method with any sort of decorator, ty falls back to typing the variable as Unknown, unless the decorated method also contains a type hint.
Example:
from functools import cache
from typing import reveal_type
class WithoutDecorator:
def __init__(self):
self.x: int = 3
def set_x(self) -> None:
self.x = 4
class WithDecorator:
def __init__(self):
self.x: int = 3
@cache
def set_x(self) -> None:
self.x = 4
class WithDecoratorAndAnnotation:
def __init__(self):
self.x: int = 3
@cache
def set_x(self) -> None:
self.x: int = 4
reveal_type(WithoutDecorator().x) # int
reveal_type(WithDecorator().x) # Unknown | int
reveal_type(WithDecoratorAndAnnotation().x) # intVersion
ty 0.0.12 (4b74e4d 2026-01-14)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels