Skip to content

Commit

Permalink
Update @property attributes to @cached_property part 1 (#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownPlatypus authored Oct 31, 2023
1 parent 41b86f7 commit da9784e
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 117 deletions.
2 changes: 0 additions & 2 deletions django-stubs/contrib/staticfiles/storage.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ from typing_extensions import TypeAlias
_PostProcessT: TypeAlias = Iterator[tuple[str, str, bool] | tuple[str, None, RuntimeError]]

class StaticFilesStorage(FileSystemStorage):
base_location: str
location: _PathCompatible
def __init__(
self, location: _PathCompatible | None = ..., base_url: str | None = ..., *args: Any, **kwargs: Any
) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/core/files/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from types import TracebackType
from typing import IO, AnyStr, type_check_only

from django.core.files.utils import FileProxyMixin
from django.utils.functional import cached_property
from typing_extensions import Self

class File(FileProxyMixin[AnyStr], IO[AnyStr]):
Expand All @@ -13,7 +14,7 @@ class File(FileProxyMixin[AnyStr], IO[AnyStr]):
def __init__(self, file: IO[AnyStr] | None, name: str | None = ...) -> None: ...
def __bool__(self) -> bool: ...
def __len__(self) -> int: ...
@property
@cached_property
def size(self) -> int: ...
def chunks(self, chunk_size: int | None = ...) -> Iterator[AnyStr]: ...
def multiple_chunks(self, chunk_size: int | None = ...) -> bool | None: ...
Expand All @@ -32,7 +33,6 @@ class File(FileProxyMixin[AnyStr], IO[AnyStr]):

class ContentFile(File[AnyStr]):
file: IO[AnyStr]
size: int
def __init__(self, content: AnyStr, name: str | None = ...) -> None: ...
def __bool__(self) -> bool: ...
def open(self, mode: str | None = ...) -> Self: ...
Expand Down
11 changes: 6 additions & 5 deletions django-stubs/core/files/storage/filesystem.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from collections.abc import Sequence
from typing import Any

from django.utils._os import _PathCompatible
from django.utils.functional import cached_property

from .base import Storage
from .mixins import StorageSettingsMixin
Expand All @@ -16,14 +17,14 @@ class FileSystemStorage(Storage, StorageSettingsMixin):
file_permissions_mode: int | None = ...,
directory_permissions_mode: int | None = ...,
) -> None: ...
@property
@cached_property
def base_location(self) -> _PathCompatible: ...
@property
@cached_property
def location(self) -> _PathCompatible: ...
@property
@cached_property
def base_url(self) -> str: ...
@property
@cached_property
def file_permissions_mode(self) -> int | None: ...
@property
@cached_property
def directory_permissions_mode(self) -> int | None: ...
def deconstruct(obj) -> tuple[str, Sequence[Any], dict[str, Any]]: ... # fake
3 changes: 2 additions & 1 deletion django-stubs/core/files/storage/handler.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import Any

from django.core.exceptions import ImproperlyConfigured
from django.utils.functional import cached_property

from .base import Storage

class InvalidStorageError(ImproperlyConfigured): ...

class StorageHandler:
def __init__(self, backends: dict[str, Storage] | None = ...) -> None: ...
@property
@cached_property
def backends(self) -> dict[str, Storage]: ...
def __getitem__(self, alias: str) -> Storage: ...
def create_storage(self, params: dict[str, Any]) -> Storage: ...
11 changes: 6 additions & 5 deletions django-stubs/core/files/storage/memory.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from collections.abc import Sequence
from typing import Any

from django.utils._os import _PathCompatible
from django.utils.functional import cached_property

from .base import Storage
from .mixins import StorageSettingsMixin
Expand All @@ -14,14 +15,14 @@ class InMemoryStorage(Storage, StorageSettingsMixin):
file_permissions_mode: int | None = ...,
directory_permissions_mode: int | None = ...,
) -> None: ...
@property
@cached_property
def base_location(self) -> _PathCompatible: ...
@property
@cached_property
def location(self) -> _PathCompatible: ...
@property
@cached_property
def base_url(self) -> str: ...
@property
@cached_property
def file_permissions_mode(self) -> int | None: ...
@property
@cached_property
def directory_permissions_mode(self) -> int | None: ...
def deconstruct(obj) -> tuple[str, Sequence[Any], dict[str, Any]]: ... # fake
5 changes: 3 additions & 2 deletions django-stubs/core/handlers/asgi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from django.http.request import HttpRequest, _ImmutableQueryDict
from django.http.response import HttpResponseBase
from django.urls.resolvers import ResolverMatch, URLResolver
from django.utils.datastructures import MultiValueDict
from django.utils.functional import cached_property
from typing_extensions import TypeAlias

_ReceiveCallback: TypeAlias = Callable[[], Awaitable[Mapping[str, Any]]]
Expand All @@ -22,11 +23,11 @@ class ASGIRequest(HttpRequest):
method: str
META: dict[str, Any]
def __init__(self, scope: Mapping[str, Any], body_file: IO[bytes]) -> None: ...
@property
@cached_property
def GET(self) -> _ImmutableQueryDict: ... # type: ignore[override]
POST: _ImmutableQueryDict
FILES: MultiValueDict
@property
@cached_property
def COOKIES(self) -> dict[str, str]: ... # type: ignore[override]

_T = TypeVar("_T")
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/core/management/commands/loaddata.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from collections.abc import Sequence
from django.apps.config import AppConfig
from django.core.management.base import BaseCommand
from django.db.models.base import Model
from django.utils.functional import cached_property

has_bz2: bool
has_lzma: bool
Expand All @@ -22,7 +23,7 @@ class Command(BaseCommand):
def loaddata(self, fixture_labels: Sequence[str]) -> None: ...
def load_label(self, fixture_label: str) -> None: ...
def find_fixtures(self, fixture_label: str) -> list[tuple[str, str | None, str | None]]: ...
@property
@cached_property
def fixture_dirs(self) -> list[str]: ...
def parse_name(self, fixture_name: str) -> tuple[str, str | None, str | None]: ...

Expand Down
7 changes: 4 additions & 3 deletions django-stubs/core/management/commands/makemessages.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from re import Pattern
from typing import Any

from django.core.management.base import BaseCommand
from django.utils.functional import cached_property

plural_forms_re: Pattern[str]
STATUS_OK: int
Expand All @@ -21,11 +22,11 @@ class BuildFile:
"""

def __init__(self, command: BaseCommand, domain: str, translatable: TranslatableFile) -> None: ...
@property
@cached_property
def is_templatized(self) -> bool: ...
@property
@cached_property
def path(self) -> str: ...
@property
@cached_property
def work_path(self) -> str: ...
def preprocess(self) -> None: ...
def postprocess_messages(self, msgs: str) -> str: ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/core/paginator.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Iterable, Iterator, Sequence, Sized
from typing import ClassVar, Generic, Protocol, TypeVar, overload

from django.utils.functional import _StrPromise
from django.utils.functional import _StrPromise, cached_property

class UnorderedObjectListWarning(RuntimeWarning): ...
class InvalidPage(Exception): ...
Expand Down Expand Up @@ -33,9 +33,9 @@ class Paginator(Generic[_T]):
def validate_number(self, number: int | float | str) -> int: ...
def get_page(self, number: int | float | str | None) -> Page[_T]: ...
def page(self, number: int | str) -> Page[_T]: ...
@property
@cached_property
def count(self) -> int: ...
@property
@cached_property
def num_pages(self) -> int: ...
@property
def page_range(self) -> range: ...
Expand Down
5 changes: 3 additions & 2 deletions django-stubs/db/models/query.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from django.db.models import Manager
from django.db.models.base import Model
from django.db.models.expressions import Combinable
from django.db.models.sql.query import Query, RawQuery
from django.utils.functional import cached_property
from typing_extensions import Self, TypeAlias

_T = TypeVar("_T", bound=Model, covariant=True)
Expand Down Expand Up @@ -204,12 +205,12 @@ class RawQuerySet(Iterable[_T], Sized):
def __getitem__(self, k: str) -> Any: ...
@overload
def __getitem__(self, k: slice) -> RawQuerySet[_T]: ...
@property
@cached_property
def columns(self) -> list[str]: ...
@property
def db(self) -> str: ...
def iterator(self) -> Iterator[_T]: ...
@property
@cached_property
def model_fields(self) -> dict[str, str]: ...
def prefetch_related(self, *lookups: Any) -> RawQuerySet[_T]: ...
def resolve_model_init_order(self) -> tuple[list[str], list[int], list[tuple[str, int]]]: ...
Expand Down
5 changes: 3 additions & 2 deletions django-stubs/db/models/sql/compiler.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from django.db.models.base import Model
from django.db.models.expressions import BaseExpression, Expression
from django.db.models.sql.query import Query
from django.db.models.sql.subqueries import AggregateQuery, DeleteQuery, InsertQuery, UpdateQuery
from django.utils.functional import cached_property
from typing_extensions import TypeAlias

_ParamT: TypeAlias = str | int
Expand Down Expand Up @@ -129,9 +130,9 @@ class SQLInsertCompiler(SQLCompiler):

class SQLDeleteCompiler(SQLCompiler):
query: DeleteQuery
@property
@cached_property
def single_alias(self) -> bool: ...
@property
@cached_property
def contains_self_reference_subquery(self) -> bool: ...
def as_sql(self) -> _AsSqlType: ... # type: ignore[override]

Expand Down
3 changes: 2 additions & 1 deletion django-stubs/db/models/sql/query.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ from django.db.models.query_utils import PathInfo
from django.db.models.sql.compiler import SQLCompiler
from django.db.models.sql.datastructures import BaseTable, Join
from django.db.models.sql.where import WhereNode
from django.utils.functional import cached_property

JoinInfo = namedtuple("JoinInfo", ("final_field", "targets", "opts", "joins", "path", "transform_function"))

Expand Down Expand Up @@ -85,7 +86,7 @@ class Query(BaseExpression):
def output_field(self) -> Field: ...
@property
def has_select_fields(self) -> bool: ...
@property
@cached_property
def base_table(self) -> str: ...
def sql_with_params(self) -> tuple[str, tuple]: ...
def __deepcopy__(self, memo: dict[int, Any]) -> Query: ...
Expand Down
5 changes: 3 additions & 2 deletions django-stubs/db/models/sql/where.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from django.db.models.expressions import Expression
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
from django.db.models.sql.query import Query
from django.utils import tree
from django.utils.functional import cached_property

AND: str
OR: str
Expand All @@ -23,9 +24,9 @@ class WhereNode(tree.Node):
def clone(self) -> WhereNode: ...
def relabeled_clone(self, change_map: dict[str | None, str]) -> WhereNode: ...
def resolve_expression(self, *args: Any, **kwargs: Any) -> WhereNode: ...
@property
@cached_property
def contains_aggregate(self) -> bool: ...
@property
@cached_property
def contains_over_clause(self) -> bool: ...
@property
def is_summary(self) -> bool: ...
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/db/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from django.apps import AppConfig
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Model
from django.utils.connection import BaseConnectionHandler
from django.utils.functional import cached_property

DEFAULT_DB_ALIAS: str
DJANGO_VERSION_PICKLE_KEY: str
Expand Down Expand Up @@ -42,7 +43,7 @@ class ConnectionHandler(BaseConnectionHandler[BaseDatabaseWrapper]):

class ConnectionRouter:
def __init__(self, routers: Iterable[Any] | None = ...) -> None: ...
@property
@cached_property
def routers(self) -> list[Any]: ...
def db_for_read(self, model: type[Model], **hints: Any) -> str: ...
def db_for_write(self, model: type[Model], **hints: Any) -> str: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/forms/boundfield.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from django.forms.forms import BaseForm
from django.forms.renderers import BaseRenderer
from django.forms.utils import ErrorList
from django.forms.widgets import Widget
from django.utils.functional import _StrOrPromise
from django.utils.functional import _StrOrPromise, cached_property
from django.utils.safestring import SafeString
from typing_extensions import TypeAlias

Expand All @@ -22,7 +22,7 @@ class BoundField:
label: _StrOrPromise
help_text: _StrOrPromise
def __init__(self, form: BaseForm, field: Field, name: str) -> None: ...
@property
@cached_property
def subwidgets(self) -> list[BoundWidget]: ...
def __bool__(self) -> bool: ...
def __iter__(self) -> Iterator[BoundWidget]: ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/forms/forms.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from django.forms.fields import Field
from django.forms.renderers import BaseRenderer
from django.forms.utils import ErrorDict, ErrorList, RenderableFormMixin, _DataT, _FilesT
from django.forms.widgets import Media, MediaDefiningClass
from django.utils.functional import _StrOrPromise
from django.utils.functional import _StrOrPromise, cached_property
from django.utils.safestring import SafeString

class DeclarativeFieldsMetaclass(MediaDefiningClass): ...
Expand Down Expand Up @@ -65,7 +65,7 @@ class BaseForm(RenderableFormMixin):
def full_clean(self) -> None: ...
def clean(self) -> dict[str, Any] | None: ...
def has_changed(self) -> bool: ...
@property
@cached_property
def changed_data(self) -> list[str]: ...
@property
def media(self) -> Media: ...
Expand Down
5 changes: 3 additions & 2 deletions django-stubs/forms/formsets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from django.db.models.fields import _ErrorMessagesDict
from django.forms.forms import BaseForm, Form
from django.forms.utils import ErrorList, RenderableFormMixin, _DataT, _FilesT
from django.forms.widgets import Media, Widget
from django.utils.functional import cached_property

TOTAL_FORM_COUNT: str
INITIAL_FORM_COUNT: str
Expand Down Expand Up @@ -65,11 +66,11 @@ class BaseFormSet(Generic[_F], Sized, RenderableFormMixin):
def __getitem__(self, index: int) -> _F: ...
def __len__(self) -> int: ...
def __bool__(self) -> bool: ...
@property
@cached_property
def management_form(self) -> ManagementForm: ...
def total_form_count(self) -> int: ...
def initial_form_count(self) -> int: ...
@property
@cached_property
def forms(self) -> list[_F]: ...
def get_form_kwargs(self, index: int | None) -> dict[str, Any]: ...
@property
Expand Down
5 changes: 3 additions & 2 deletions django-stubs/forms/renderers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from django.template.backends.base import BaseEngine
from django.template.backends.django import DjangoTemplates as DjangoTemplatesR
from django.template.backends.jinja2 import Jinja2 as Jinja2R
from django.template.base import Template
from django.utils.functional import cached_property

def get_default_renderer() -> BaseRenderer: ...

Expand All @@ -16,14 +17,14 @@ class BaseRenderer:

class EngineMixin:
def get_template(self, template_name: str) -> Any: ...
@property
@cached_property
def engine(self) -> BaseEngine: ...

class DjangoTemplates(EngineMixin, BaseRenderer):
backend: type[DjangoTemplatesR]

class Jinja2(EngineMixin, BaseRenderer):
@property
@cached_property
def backend(self) -> type[Jinja2R]: ...

class Jinja2DivFormRenderer(Jinja2):
Expand Down
8 changes: 8 additions & 0 deletions django-stubs/http/request.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class HttpHeaders(CaseInsensitiveMapping[str]):
def __init__(self, environ: Mapping[str, Any]) -> None: ...
@classmethod
def parse_header_name(cls, header: str) -> str | None: ...
@classmethod
def to_wsgi_name(cls, header: str) -> str: ...
@classmethod
def to_asgi_name(cls, header: str) -> str: ...
@classmethod
def to_wsgi_names(cls, headers: Mapping[str, Any]) -> dict[str, Any]: ...
@classmethod
def to_asgi_names(cls, headers: Mapping[str, Any]) -> dict[str, Any]: ...

class HttpRequest(BytesIO):
GET: _ImmutableQueryDict
Expand Down
Loading

0 comments on commit da9784e

Please sign in to comment.