Skip to content

Reassigned @property is typed as Callable #13975

Closed
@Avasam

Description

@Avasam

Bug Report

Mypy seems to forget about the @property decorator if the property is aliased.

To Reproduce

class MyClass:
    def error(self) -> bool:
        # Incompatible return value type (got "Callable[[], bool]", expected "bool")  [return-value]
        return self.prop_alias

    def works(self) -> bool:
        # No error
        return self.prop

    @property
    def prop(self) -> bool:
        return True

    prop_alias = prop


some_boolean: bool

instance = MyClass()
# Incompatible types in assignment (expression has type "Callable[[], bool]", variable has type "bool")  [assignment]
some_boolean = instance.prop_alias
# No error
some_boolean = instance.prop

Expected Behavior

prop_alias should be usable as a boolean, just like prop

Actual Behavior

prop_alias is seen as a Callable

Your Environment

  • Mypy version used: 0.982 (compiled: yes)
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
show_error_codes = True
strict = False
namespace_packages = True
  • Python version used: 3.9.13

I'm not sure if this is related to #2563 and #11619

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions