Skip to content

Commit

Permalink
Fix @classproperty decorator (#1287)
Browse files Browse the repository at this point in the history
Removed unnecessary `Self` hints on classproperty methods.

The removal of `self: Self` fixes #1285. Regressed in #1253.
  • Loading branch information
intgr authored Dec 9, 2022
1 parent 090aea6 commit 16fde01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions django-stubs/utils/functional.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def partition(
_Get = TypeVar("_Get", covariant=True)

class classproperty(Generic[_Get]):
fget: Callable[[Self], _Get] | None
def __init__(self: Self, method: Callable[[Self], _Get] | None = ...) -> None: ...
def __get__(self: Self, instance: Self | None, cls: type[Self] = ...) -> _Get: ...
def getter(self: Self, method: Callable[[Self], _Get]) -> classproperty[_Get]: ...
fget: Callable[[Any], _Get] | None
def __init__(self, method: Callable[[Any], _Get] | None = ...) -> None: ...
def __get__(self, instance: Any | None, cls: type[Any] = ...) -> _Get: ...
def getter(self, method: Callable[[Any], _Get]) -> classproperty[_Get]: ...

class _Getter(Protocol[_Get]):
"""Type fake to declare some read-only properties (until `property` builtin is generic)
Expand Down
18 changes: 18 additions & 0 deletions tests/typecheck/utils/test_functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,21 @@
foo(s) # E: Argument 1 to "foo" has incompatible type "_StrPromise"; expected "str"
bar(s)
- case: classproperty_usage
main: |
from typing import Any
from django.utils.functional import classproperty
class Foo:
@classproperty
def attr(cls: Any) -> str: ...
reveal_type(attr) # N: Revealed type is "django.utils.functional.classproperty[builtins.str]"
reveal_type(attr.getter) # N: Revealed type is "def (method: def (Any) -> builtins.str) -> django.utils.functional.classproperty[builtins.str]"
reveal_type(Foo.attr) # N: Revealed type is "builtins.str"
class Bar(Foo):
def method(self) -> None:
reveal_type(self.attr) # N: Revealed type is "builtins.str"

0 comments on commit 16fde01

Please sign in to comment.