Skip to content

Reassigned @property is typed as Callable #13975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Avasam opened this issue Oct 31, 2022 · 4 comments
Closed

Reassigned @property is typed as Callable #13975

Avasam opened this issue Oct 31, 2022 · 4 comments
Labels
bug mypy got something wrong

Comments

@Avasam
Copy link
Contributor

Avasam commented Oct 31, 2022

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

@Avasam Avasam added the bug mypy got something wrong label Oct 31, 2022
@Avasam Avasam changed the title @property alias is typed as Callable Reassigend @property is typed as Callable Nov 9, 2022
@Avasam Avasam changed the title Reassigend @property is typed as Callable Reassigned @property is typed as Callable Nov 9, 2022
@niklasmohrin
Copy link

niklasmohrin commented Jan 16, 2023

Same behavior on

$ mypy --version
mypy 0.991 (compiled: no)
$ python --version
Python 3.10.9

without config. Result:

class Foo:
    @property
    def bar(self):
        return 42

    baz = bar

x: int = Foo().bar  # works
# x: int = Foo().baz  # error: Incompatible types in assignment (expression has type "Callable[[], Any]", variable has type "int")  [assignment]

@finite-state-machine
Copy link

Issue is confirmed to affect both 1.8 and master.
mypy-play.net gist

@finite-state-machine
Copy link

This might be the same as #6700.

@Avasam
Copy link
Contributor Author

Avasam commented Jan 26, 2024

This might be the same as #6700.

You are right. Closing as duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants