Skip to content

Assignment in decorated method causes fallback to Unknown #2566

@philj56

Description

@philj56

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)  # int

Version

ty 0.0.12 (4b74e4d 2026-01-14)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions