Skip to content

False negative when accessing annotated class attributes #13103

Closed
@denballakh

Description

@denballakh

Consider this example:

class X:
    __slots__ = ('a',)
    a: int

print(X.a) # <member 'a' of 'X' objects>
reveal_type(X.a) # builtins.int
reveal_type(X.a.__get__) # Any
    # "int" has no attribute "__get__"; maybe "__gt__", "__ge__", or "__ne__"?

I expect to get member_descriptor and some Callable, but instead i see two wrong reveals and one error.

I can use this bug to write unsafe code:

class X:
    __slots__ = ('a',)
    a: int

x = X()
x.a = X.a # no error!
assert isinstance(x.a, int), x.a
# AssertionError: <member 'a' of 'X' objects>

My Environment

  • mypy 0.961 (compiled: no)
  • no command-line flags, no config file
  • CPython 3.10.4
  • Windows 10

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions