Skip to content

Commit a80f51c

Browse files
Update some cached_property
1 parent 086968b commit a80f51c

File tree

26 files changed

+62
-114
lines changed

26 files changed

+62
-114
lines changed

django-stubs/contrib/auth/forms.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ class AdminPasswordChangeForm(forms.Form):
104104
def clean_password2(self) -> str: ...
105105
def save(self, commit: bool = ...) -> AbstractBaseUser: ...
106106
@property
107-
def changed_data(self) -> list[str]: ...
107+
def changed_data(self) -> list[str]: ... # type: ignore[override]

django-stubs/contrib/staticfiles/storage.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ from typing_extensions import TypeAlias
1010
_PostProcessT: TypeAlias = Iterator[tuple[str, str, bool] | tuple[str, None, RuntimeError]]
1111

1212
class StaticFilesStorage(FileSystemStorage):
13-
base_location: str
14-
location: _PathCompatible
1513
def __init__(
1614
self, location: _PathCompatible | None = ..., base_url: str | None = ..., *args: Any, **kwargs: Any
1715
) -> None: ...

django-stubs/core/files/base.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from types import TracebackType
33
from typing import IO, AnyStr, type_check_only
44

55
from django.core.files.utils import FileProxyMixin
6+
from django.utils.functional import cached_property
67
from typing_extensions import Self
78

89
class File(FileProxyMixin[AnyStr], IO[AnyStr]):
@@ -13,7 +14,7 @@ class File(FileProxyMixin[AnyStr], IO[AnyStr]):
1314
def __init__(self, file: IO[AnyStr] | None, name: str | None = ...) -> None: ...
1415
def __bool__(self) -> bool: ...
1516
def __len__(self) -> int: ...
16-
@property
17+
@cached_property
1718
def size(self) -> int: ...
1819
def chunks(self, chunk_size: int | None = ...) -> Iterator[AnyStr]: ...
1920
def multiple_chunks(self, chunk_size: int | None = ...) -> bool | None: ...
@@ -32,7 +33,6 @@ class File(FileProxyMixin[AnyStr], IO[AnyStr]):
3233

3334
class ContentFile(File[AnyStr]):
3435
file: IO[AnyStr]
35-
size: int
3636
def __init__(self, content: AnyStr, name: str | None = ...) -> None: ...
3737
def __bool__(self) -> bool: ...
3838
def open(self, mode: str | None = ...) -> Self: ...

django-stubs/core/files/storage/filesystem.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from collections.abc import Sequence
22
from typing import Any
33

44
from django.utils._os import _PathCompatible
5+
from django.utils.functional import cached_property
56

67
from .base import Storage
78
from .mixins import StorageSettingsMixin
@@ -16,14 +17,14 @@ class FileSystemStorage(Storage, StorageSettingsMixin):
1617
file_permissions_mode: int | None = ...,
1718
directory_permissions_mode: int | None = ...,
1819
) -> None: ...
19-
@property
20+
@cached_property
2021
def base_location(self) -> _PathCompatible: ...
21-
@property
22+
@cached_property
2223
def location(self) -> _PathCompatible: ...
23-
@property
24+
@cached_property
2425
def base_url(self) -> str: ...
25-
@property
26+
@cached_property
2627
def file_permissions_mode(self) -> int | None: ...
27-
@property
28+
@cached_property
2829
def directory_permissions_mode(self) -> int | None: ...
2930
def deconstruct(obj) -> tuple[str, Sequence[Any], dict[str, Any]]: ... # fake
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from typing import Any
22

33
from django.core.exceptions import ImproperlyConfigured
4+
from django.utils.functional import cached_property
45

56
from .base import Storage
67

78
class InvalidStorageError(ImproperlyConfigured): ...
89

910
class StorageHandler:
1011
def __init__(self, backends: dict[str, Storage] | None = ...) -> None: ...
11-
@property
12+
@cached_property
1213
def backends(self) -> dict[str, Storage]: ...
1314
def __getitem__(self, alias: str) -> Storage: ...
1415
def create_storage(self, params: dict[str, Any]) -> Storage: ...

django-stubs/core/files/storage/memory.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from collections.abc import Sequence
22
from typing import Any
33

44
from django.utils._os import _PathCompatible
5+
from django.utils.functional import cached_property
56

67
from .base import Storage
78
from .mixins import StorageSettingsMixin
@@ -14,14 +15,14 @@ class InMemoryStorage(Storage, StorageSettingsMixin):
1415
file_permissions_mode: int | None = ...,
1516
directory_permissions_mode: int | None = ...,
1617
) -> None: ...
17-
@property
18+
@cached_property
1819
def base_location(self) -> _PathCompatible: ...
19-
@property
20+
@cached_property
2021
def location(self) -> _PathCompatible: ...
21-
@property
22+
@cached_property
2223
def base_url(self) -> str: ...
23-
@property
24+
@cached_property
2425
def file_permissions_mode(self) -> int | None: ...
25-
@property
26+
@cached_property
2627
def directory_permissions_mode(self) -> int | None: ...
2728
def deconstruct(obj) -> tuple[str, Sequence[Any], dict[str, Any]]: ... # fake

django-stubs/core/handlers/asgi.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from django.http.request import HttpRequest, _ImmutableQueryDict
66
from django.http.response import HttpResponseBase
77
from django.urls.resolvers import ResolverMatch, URLResolver
88
from django.utils.datastructures import MultiValueDict
9+
from django.utils.functional import cached_property
910
from typing_extensions import TypeAlias
1011

1112
_ReceiveCallback: TypeAlias = Callable[[], Awaitable[Mapping[str, Any]]]
@@ -22,11 +23,11 @@ class ASGIRequest(HttpRequest):
2223
method: str
2324
META: dict[str, Any]
2425
def __init__(self, scope: Mapping[str, Any], body_file: IO[bytes]) -> None: ...
25-
@property
26+
@cached_property
2627
def GET(self) -> _ImmutableQueryDict: ... # type: ignore[override]
2728
POST: _ImmutableQueryDict
2829
FILES: MultiValueDict
29-
@property
30+
@cached_property
3031
def COOKIES(self) -> dict[str, str]: ... # type: ignore[override]
3132

3233
_T = TypeVar("_T")

django-stubs/core/management/commands/loaddata.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from collections.abc import Sequence
44
from django.apps.config import AppConfig
55
from django.core.management.base import BaseCommand
66
from django.db.models.base import Model
7+
from django.utils.functional import cached_property
78

89
READ_STDIN: str
910

@@ -19,7 +20,7 @@ class Command(BaseCommand):
1920
def loaddata(self, fixture_labels: Sequence[str]) -> None: ...
2021
def load_label(self, fixture_label: str) -> None: ...
2122
def find_fixtures(self, fixture_label: str) -> list[tuple[str, str | None, str | None]]: ...
22-
@property
23+
@cached_property
2324
def fixture_dirs(self) -> list[str]: ...
2425
def parse_name(self, fixture_name: str) -> tuple[str, str | None, str | None]: ...
2526

django-stubs/core/management/commands/makemessages.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from re import Pattern
22
from typing import Any
33

44
from django.core.management.base import BaseCommand
5+
from django.utils.functional import cached_property
56

67
plural_forms_re: Pattern[str]
78
STATUS_OK: int
@@ -21,11 +22,11 @@ class BuildFile:
2122
"""
2223

2324
def __init__(self, command: BaseCommand, domain: str, translatable: TranslatableFile) -> None: ...
24-
@property
25+
@cached_property
2526
def is_templatized(self) -> bool: ...
26-
@property
27+
@cached_property
2728
def path(self) -> str: ...
28-
@property
29+
@cached_property
2930
def work_path(self) -> str: ...
3031
def preprocess(self) -> None: ...
3132
def postprocess_messages(self, msgs: str) -> str: ...

django-stubs/core/paginator.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Iterable, Iterator, Sequence, Sized
22
from typing import Generic, Protocol, TypeVar, overload
33

4+
from django.utils.functional import cached_property
45
from typing_extensions import TypeAlias
56

67
class UnorderedObjectListWarning(RuntimeWarning): ...
@@ -32,9 +33,9 @@ class Paginator(Generic[_T]):
3233
def validate_number(self, number: int | float | str) -> int: ...
3334
def get_page(self, number: int | float | str | None) -> Page[_T]: ...
3435
def page(self, number: int | str) -> Page[_T]: ...
35-
@property
36+
@cached_property
3637
def count(self) -> int: ...
37-
@property
38+
@cached_property
3839
def num_pages(self) -> int: ...
3940
@property
4041
def page_range(self) -> range: ...

0 commit comments

Comments
 (0)