Skip to content

5.0: Update django.contrib.sitemaps, django.contrib.staticfiles #2076

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

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions django-stubs/contrib/sitemaps/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ from django.core.paginator import Paginator
from django.db.models.base import Model
from django.db.models.query import QuerySet

PING_URL: str

class SitemapNotFound(Exception): ...

def ping_google(sitemap_url: str | None = ..., ping_url: str = ..., sitemap_uses_https: bool = ...) -> None: ...

_ItemT = TypeVar("_ItemT")

class Sitemap(Generic[_ItemT]):
Expand Down
Empty file.
Empty file.

This file was deleted.

3 changes: 2 additions & 1 deletion django-stubs/contrib/sites/requests.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import NoReturn

from django.db.models.base import ModelBase
from django.http.request import HttpRequest

class RequestSite:
name: str
domain: str
def __init__(self, request: HttpRequest) -> None: ...
def save(self, force_insert: bool = ..., force_update: bool = ...) -> NoReturn: ...
def save(self, force_insert: bool | tuple[ModelBase, ...] = ..., force_update: bool = ...) -> NoReturn: ...
def delete(self) -> NoReturn: ...
5 changes: 4 additions & 1 deletion django-stubs/contrib/staticfiles/checks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ from collections.abc import Sequence
from typing import Any

from django.apps.config import AppConfig
from django.core.checks.messages import CheckMessage
from django.core.checks.messages import CheckMessage, Error

E005: Error

def check_finders(app_configs: Sequence[AppConfig] | None = ..., **kwargs: Any) -> list[CheckMessage]: ...
def check_storages(app_configs: Sequence[AppConfig] | None = ..., **kwargs: Any) -> list[CheckMessage]: ...
2 changes: 1 addition & 1 deletion django-stubs/contrib/staticfiles/finders.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BaseFinder:
class FileSystemFinder(BaseFinder):
locations: list[tuple[str, str]]
storages: dict[str, Any]
def __init__(self, app_names: Sequence[str] = ..., *args: Any, **kwargs: Any) -> None: ...
def __init__(self, app_names: Sequence[str] | None = ..., *args: Any, **kwargs: Any) -> None: ...
def find_location(self, root: str, path: str, prefix: str | None = ...) -> str | None: ...
@overload
def find(self, path: str, all: Literal[False] = ...) -> str | None: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from typing import Any

from django.core.files.storage import Storage
from django.core.management.base import BaseCommand
from django.utils.functional import cached_property

class Command(BaseCommand):
copied_files: Any
Expand All @@ -10,7 +11,7 @@ class Command(BaseCommand):
post_processed_files: Any
storage: Any
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
@property
@cached_property
def local(self) -> bool: ...
interactive: Any
verbosity: Any
Expand All @@ -21,6 +22,7 @@ class Command(BaseCommand):
post_process: Any
def set_options(self, **options: Any) -> None: ...
def collect(self) -> dict[str, list[str]]: ...
def handle(self, **options: Any) -> str | None: ...
def log(self, msg: str, level: int = ...) -> None: ...
def is_local_storage(self) -> bool: ...
def clear_dir(self, path: str) -> None: ...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any

from django.core.management.base import LabelCommand

class Command(LabelCommand): ...
class Command(LabelCommand):
def handle_label(self, path: str, **options: Any) -> str | None: ... # type: ignore[override]
9 changes: 6 additions & 3 deletions django-stubs/contrib/staticfiles/storage.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import Callable, Iterator
from re import Match
from typing import Any

from django.core.files.base import File
Expand All @@ -23,10 +24,12 @@ class HashedFilesMixin:
hashed_files: Any
keep_intermediate_files: bool
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def file_hash(self, name: str, content: File = ...) -> str: ...
def file_hash(self, name: str, content: File | None = ...) -> str | None: ...
def hashed_name(self, name: str, content: File | None = ..., filename: str | None = ...) -> str: ...
def url(self, name: str, force: bool = ...) -> str: ...
def url_converter(self, name: str, hashed_files: dict[str, Any], template: str = ...) -> Callable: ...
def url_converter(
self, name: str, hashed_files: dict[str, Any], template: str | None = ...
) -> Callable[[Match], str]: ...
def post_process(self, paths: dict[str, Any], dry_run: bool = ..., **options: Any) -> _PostProcessT: ...
def clean_name(self, name: str) -> str: ...
def hash_key(self, name: str) -> str: ...
Expand All @@ -40,7 +43,7 @@ class ManifestFilesMixin(HashedFilesMixin):
manifest_storage: Storage | None
hashed_files: dict[str, str]
manifest_hash: str
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def __init__(self, *args: Any, manifest_storage: Storage | None = ..., **kwargs: Any) -> None: ...
def read_manifest(self) -> str: ...
def load_manifest(self) -> dict[str, Any]: ...
def save_manifest(self) -> None: ...
Expand Down
6 changes: 3 additions & 3 deletions django-stubs/db/models/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ class Model(metaclass=ModelBase):
def get_constraints(self) -> list[tuple[type[Model], Sequence[BaseConstraint]]]: ...
def save(
self,
force_insert: bool = ...,
force_insert: bool | tuple[ModelBase, ...] = ...,
force_update: bool = ...,
using: str | None = ...,
update_fields: Iterable[str] | None = ...,
) -> None: ...
async def asave(
self,
force_insert: bool = ...,
force_insert: bool | tuple[ModelBase, ...] = ...,
force_update: bool = ...,
using: str | None = ...,
update_fields: Iterable[str] | None = ...,
) -> None: ...
def save_base(
self,
raw: bool = ...,
force_insert: bool = ...,
force_insert: bool | tuple[ModelBase, ...] = ...,
force_update: bool = ...,
using: str | None = ...,
update_fields: Iterable[str] | None = ...,
Expand Down
2 changes: 2 additions & 0 deletions scripts/django_tests_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
"django.contrib.sessions",
"django.contrib.sites",
]

STATIC_URL = "static/"
6 changes: 5 additions & 1 deletion scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ django.conf.locale.*
# We don't need migrations:
django.contrib.admin.migrations.*
django.contrib.auth.migrations.*
django.contrib.flatpages.migrations.*
django.contrib.contenttypes.migrations.*
django.contrib.flatpages.migrations.*
django.contrib.redirects.migrations.*
django.contrib.sessions.migrations.*
django.contrib.sites.migrations.*

# default_storage is actually an instance of DefaultStorage, but it proxies through to a Storage
django.core.files.storage.default_storage
Expand Down Expand Up @@ -195,6 +198,7 @@ django.contrib.gis.gdal.raster.source.GDALRaster.is_vsi_based
django.contrib.postgres.expressions.ArraySubquery.output_field
django.contrib.postgres.indexes.PostgresIndex.max_name_length
django.contrib.sessions.backends.db.SessionStore.model
django.contrib.staticfiles.management.commands.collectstatic.Command.local
django.core.files.File.size
django.core.files.base.File.size
django.core.files.storage.FileSystemStorage.base_location
Expand Down
5 changes: 1 addition & 4 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,7 @@ django.contrib.sites.models.Site.redirect_set
django.contrib.sites.models.SiteManager.__slotnames__
django.contrib.staticfiles.finders.BaseStorageFinder.storage
django.contrib.staticfiles.finders.DefaultStorageFinder.storage
django.contrib.staticfiles.finders.FileSystemFinder.__init__
django.contrib.staticfiles.management.commands.collectstatic
django.contrib.staticfiles.management.commands.findstatic.Command.handle_label
django.contrib.staticfiles.storage
django.contrib.staticfiles.storage.staticfiles_storage
django.core.cache.cache
django.core.checks.registry.CheckRegistry.register
django.core.files.locks.OVERLAPPED
Expand Down
13 changes: 0 additions & 13 deletions scripts/stubtest/allowlist_todo_django50.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ django.contrib.messages.storage.cookie.MessagePartSerializer
django.contrib.messages.storage.cookie.bisect_keep_left
django.contrib.messages.storage.cookie.bisect_keep_right
django.contrib.messages.test
django.contrib.redirects.migrations.0001_initial
django.contrib.redirects.migrations.0002_alter_redirect_new_path_help_text
django.contrib.sessions.migrations.0001_initial
django.contrib.sitemaps.PING_URL
django.contrib.sitemaps.SitemapNotFound
django.contrib.sitemaps.management
django.contrib.sitemaps.management.commands
django.contrib.sitemaps.management.commands.ping_google
django.contrib.sitemaps.ping_google
django.contrib.sites.migrations.0001_initial
django.contrib.sites.migrations.0002_alter_domain_unique
django.contrib.staticfiles.checks.E005
django.contrib.staticfiles.checks.check_storages
django.db.backends.base.features.BaseDatabaseFeatures.delete_can_self_reference_subquery
django.db.backends.base.features.BaseDatabaseFeatures.insert_test_table_with_defaults
django.db.backends.base.features.BaseDatabaseFeatures.supports_default_keyword_in_bulk_insert
Expand Down
3 changes: 0 additions & 3 deletions tests/typecheck/test_import_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@
import django.contrib.sessions.serializers
import django.contrib.sitemaps
import django.contrib.sitemaps.apps
import django.contrib.sitemaps.management
import django.contrib.sitemaps.management.commands
import django.contrib.sitemaps.management.commands.ping_google
import django.contrib.sitemaps.views
import django.contrib.sites
import django.contrib.sites.admin
Expand Down
Loading