Skip to content

classproperty decorator overriding attributes does not seem to be working properly #1367

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

Open
PedroPerpetua opened this issue Feb 16, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@PedroPerpetua
Copy link

PedroPerpetua commented Feb 16, 2023

Bug report

What's wrong

The classproperty decorator, when used to override a superclass property, fails with an error of Signature of <property> incompatible with supertype <Superclass>; I thought this was related to this issue in mypy, but mypy 1.0.0 has been released with this issue fixed and yet this specific case does not work properly.

from typing import reveal_type
from django.utils.functional import classproperty

class Superclass:
    prop = 3

class Subclass(Superclass):
    @classproperty
    def prop(self) -> int:
        return 6

reveal_type(Subclass.prop)  # Runtime type is 'int', as expected
# Mypy fails with "error: Signature of 'prop' incompatible with supertype 'Superclass'"

How is that should be

Mypy should correctly identify that prop works as a property and returns an int, being compatible with the superclass.

System information

  • OS: Windows
  • python version: 3.11.1
  • django version: 4.1.17
  • mypy version: 1.0.0
  • django-stubs version: 1.14.0
  • django-stubs-ext version: 0.7.0
@PedroPerpetua PedroPerpetua added the bug Something isn't working label Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant