Skip to content

Commit da9784e

Browse files
Update @property attributes to @cached_property part 1 (#1761)
1 parent 41b86f7 commit da9784e

File tree

26 files changed

+131
-117
lines changed

26 files changed

+131
-117
lines changed

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
has_bz2: bool
910
has_lzma: bool
@@ -22,7 +23,7 @@ class Command(BaseCommand):
2223
def loaddata(self, fixture_labels: Sequence[str]) -> None: ...
2324
def load_label(self, fixture_label: str) -> None: ...
2425
def find_fixtures(self, fixture_label: str) -> list[tuple[str, str | None, str | None]]: ...
25-
@property
26+
@cached_property
2627
def fixture_dirs(self) -> list[str]: ...
2728
def parse_name(self, fixture_name: str) -> tuple[str, str | None, str | None]: ...
2829

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections.abc import Iterable, Iterator, Sequence, Sized
22
from typing import ClassVar, Generic, Protocol, TypeVar, overload
33

4-
from django.utils.functional import _StrPromise
4+
from django.utils.functional import _StrPromise, cached_property
55

66
class UnorderedObjectListWarning(RuntimeWarning): ...
77
class InvalidPage(Exception): ...
@@ -33,9 +33,9 @@ class Paginator(Generic[_T]):
3333
def validate_number(self, number: int | float | str) -> int: ...
3434
def get_page(self, number: int | float | str | None) -> Page[_T]: ...
3535
def page(self, number: int | str) -> Page[_T]: ...
36-
@property
36+
@cached_property
3737
def count(self) -> int: ...
38-
@property
38+
@cached_property
3939
def num_pages(self) -> int: ...
4040
@property
4141
def page_range(self) -> range: ...

django-stubs/db/models/query.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ from django.db.models import Manager
77
from django.db.models.base import Model
88
from django.db.models.expressions import Combinable
99
from django.db.models.sql.query import Query, RawQuery
10+
from django.utils.functional import cached_property
1011
from typing_extensions import Self, TypeAlias
1112

1213
_T = TypeVar("_T", bound=Model, covariant=True)
@@ -204,12 +205,12 @@ class RawQuerySet(Iterable[_T], Sized):
204205
def __getitem__(self, k: str) -> Any: ...
205206
@overload
206207
def __getitem__(self, k: slice) -> RawQuerySet[_T]: ...
207-
@property
208+
@cached_property
208209
def columns(self) -> list[str]: ...
209210
@property
210211
def db(self) -> str: ...
211212
def iterator(self) -> Iterator[_T]: ...
212-
@property
213+
@cached_property
213214
def model_fields(self) -> dict[str, str]: ...
214215
def prefetch_related(self, *lookups: Any) -> RawQuerySet[_T]: ...
215216
def resolve_model_init_order(self) -> tuple[list[str], list[int], list[tuple[str, int]]]: ...

0 commit comments

Comments
 (0)