Skip to content
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

Type of generic property subclass reveals <nothing> #12731

Open
qi55wyqu opened this issue May 5, 2022 · 0 comments
Open

Type of generic property subclass reveals <nothing> #12731

qi55wyqu opened this issue May 5, 2022 · 0 comments
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes

Comments

@qi55wyqu
Copy link

qi55wyqu commented May 5, 2022

Bug Report

When subclassing property and returning a generic type, mypy reveals <nothing> as the type of the property.
Pyright reveals the expected type.

To Reproduce

from typing import Any, Generic, Optional, Type, TypeVar

T = TypeVar("T")

class customProperty(property, Generic[T]):
    def __get__(self, obj: Any, owner: Optional[Type] = None) -> T:
        return super().__get__(obj, owner)

class C:
    @customProperty
    def prop(self) -> int:
        return 1

reveal_type(C().prop)

Expected Behavior

Revealed type is "builtins.int"

Actual Behavior

Revealed type is "<nothing>"

Your Environment

  • Mypy version used: 0.950
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10
  • Operating system and version: Ubuntu 22.04

Pyright 1.1.244 however seems to get it right and returns the expected type
Type of "C().prop" is "int"

This could be related to #11115

@qi55wyqu qi55wyqu added the bug mypy got something wrong label May 5, 2022
@AlexWaygood AlexWaygood added the topic-descriptors Properties, class vs. instance attributes label May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes
Projects
None yet
Development

No branches or pull requests

2 participants