Skip to content

Attribute assignments in @staticmethods should not influence instance attributes #207

@sharkdp

Description

@sharkdp

The goal of this issue is to get rid of the TODO comments in this test. An attribute assignment in a @staticmethod should not influence the existence of implicit (instance) attributes:

class Unrelated:
    x: int

class C:
    @staticmethod
    def f(unrelated: Unrelated):
        unrelated.x = 1

reveal_type(C().x)  # should be an error

Whether or not this requires special-casing of @staticmethod during semantic index building is an open question. The answer to this question influences whether or not we can also handle the more exotic edge-cases in the mentioned test (e.g. aliased @staticmethod).

Part of: astral-sh/ruff#14164

Metadata

Metadata

Assignees

No one assigned

    Labels

    attribute accessInstance attributes, class attributes, etc.bugSomething isn't workingruntime semanticsAccurate modeling of how Python's semantics work at runtime

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions