Skip to content

Commit

Permalink
Update django.core.management.commands.* (#1829)
Browse files Browse the repository at this point in the history
* Narrow overridden `Command.handle` signatures
* Add missing entries in `BaseCommand`
* Update `runserver` command
* Update `loaddata` command
* Update `flush` Command
* Update `inspectdb` command `get_meta` signature
* Update `makemessages` command types
* Add missing allowlist entry after `cached_property` update
  • Loading branch information
UnknownPlatypus authored Nov 27, 2023
1 parent 53cdbe4 commit 5d54ac4
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Literal
from typing import Any, Literal

from _typeshed import Unused
from django.core.management import BaseCommand
from django.db.models.deletion import Collector

class Command(BaseCommand): ...
class Command(BaseCommand):
def handle(self, **options: Any) -> None: ...

class NoFastDeleteCollector(Collector):
def can_fast_delete(self, *args: Unused, **kwargs: Unused) -> Literal[False]: ...
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any

from django.core.management.base import BaseCommand

class Command(BaseCommand): ...
class Command(BaseCommand):
def handle(self, **options: Any) -> None: ...
4 changes: 4 additions & 0 deletions django-stubs/core/management/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ from django.apps.config import AppConfig
from django.core.management.color import Style
from django.utils.datastructures import _ListOrTuple

ALL_CHECKS: Literal["__all__"]

class CommandError(Exception):
def __init__(self, *args: Any, returncode: int = ..., **kwargs: Any) -> None: ...

Expand Down Expand Up @@ -49,6 +51,7 @@ class BaseCommand:
requires_system_checks: _ListOrTuple[str] | Literal["__all__"]
base_stealth_options: tuple[str, ...]
stealth_options: tuple[str, ...]
suppressed_base_arguments: set[str]
stdout: OutputWrapper
stderr: OutputWrapper
style: Style
Expand All @@ -62,6 +65,7 @@ class BaseCommand:
def get_version(self) -> str: ...
def create_parser(self, prog_name: str, subcommand: str, **kwargs: Any) -> CommandParser: ...
def add_arguments(self, parser: CommandParser) -> None: ...
def add_base_argument(self, parser: CommandParser, *args: Any, **kwargs: Any) -> None: ...
def print_help(self, prog_name: str, subcommand: str) -> None: ...
def run_from_argv(self, argv: list[str]) -> None: ...
def execute(self, *args: Any, **options: Any) -> str | None: ...
Expand Down
2 changes: 2 additions & 0 deletions django-stubs/core/management/commands/compilemessages.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Any

from django.core.management.base import BaseCommand
from django.utils._os import _PathCompatible
Expand All @@ -11,4 +12,5 @@ class Command(BaseCommand):
program_options: list[str]
verbosity: int
has_errors: bool
def handle(self, **options: Any) -> None: ...
def compile_messages(self, locations: list[tuple[_PathCompatible, _PathCompatible]]) -> None: ...
5 changes: 4 additions & 1 deletion django-stubs/core/management/commands/dbshell.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any

from django.core.management.base import BaseCommand

class Command(BaseCommand): ...
class Command(BaseCommand):
def handle(self, **options: Any) -> None: ...
1 change: 1 addition & 0 deletions django-stubs/core/management/commands/diffsettings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand
def module_to_dict(module: Any, omittable: Callable[[str], bool] = ...) -> dict[str, str]: ...

class Command(BaseCommand):
def handle(self, **options: Any) -> str: ...
def output_hash(
self, user_settings: dict[str, str], default_settings: dict[str, str], **options: Any
) -> list[str]: ...
Expand Down
5 changes: 4 additions & 1 deletion django-stubs/core/management/commands/flush.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Any

from django.core.management.base import BaseCommand
from django.core.management.color import Style

class Command(BaseCommand):
stealth_options: tuple[str]
style: Style

def handle(self, **options: Any) -> None: ...
11 changes: 9 additions & 2 deletions django-stubs/core/management/commands/inspectdb.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ from django.core.management.base import BaseCommand
from django.db.backends.base.base import BaseDatabaseWrapper

class Command(BaseCommand):
stealth_options: tuple[str]
db_module: str

def handle(self, **options: Any) -> None: ...
def handle_inspection(self, options: dict[str, Any]) -> Iterable[str]: ...
def normalize_col_name(
self, col_name: str, used_column_names: list[str], is_relation: bool
Expand All @@ -15,5 +16,11 @@ class Command(BaseCommand):
self, connection: BaseDatabaseWrapper, table_name: str, row: Any
) -> tuple[str, dict[str, Any], list[str]]: ...
def get_meta(
self, table_name: str, constraints: Any, column_to_field_name: Any, is_view: Any, is_partition: Any
self,
table_name: str,
constraints: Any,
column_to_field_name: Any,
is_view: bool,
is_partition: bool,
comment: str | None,
) -> list[str]: ...
23 changes: 22 additions & 1 deletion django-stubs/core/management/commands/loaddata.pyi
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
import zipfile
from collections.abc import Sequence
from io import BufferedReader
from typing import Callable, Literal

from django.apps.config import AppConfig
from django.core.management.base import BaseCommand
from django.core.serializers.base import DeserializedObject
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models.base import Model
from django.utils.functional import cached_property
from typing_extensions import TypeAlias

has_bz2: bool
has_lzma: bool

READ_STDIN: str
_ReadBinaryMode: TypeAlias = Literal["r", "rb"]

class Command(BaseCommand):
missing_args_message: str
ignore: bool
using: str
app_label: str
verbosity: int
excluded_models: set[type[Model]]
excluded_apps: set[AppConfig]
format: str
missing_args_message: str
fixture_count: int
loaded_object_count: int
fixture_object_count: int
models: set[type[Model]]
serialization_formats: list[str]
objs_with_deferred_fields: list[DeserializedObject]
@cached_property
def compression_formats(self) -> dict[str | None, tuple[Callable[[str, _ReadBinaryMode], BufferedReader]]]: ...
def reset_sequences(self, connection: BaseDatabaseWrapper, models: set[type[Model]]) -> None: ...
def loaddata(self, fixture_labels: Sequence[str]) -> None: ...
def save_obj(self, obj: DeserializedObject) -> bool: ...
def load_label(self, fixture_label: str) -> None: ...
def get_fixture_name_and_dirs(self, fixture_name: str) -> tuple[str, list[str]]: ...
def get_targets(self, fixture_name: str, ser_fmt: str | None, cmp_fmt: str | None) -> set[str]: ...
def find_fixture_files_in_dir(
self, fixture_dir: str, fixture_name: str, targets: set[str]
) -> list[tuple[str, str, str]]: ...
def find_fixtures(self, fixture_label: str) -> list[tuple[str, str | None, str | None]]: ...
@cached_property
def fixture_dirs(self) -> list[str]: ...
Expand Down
28 changes: 27 additions & 1 deletion django-stubs/core/management/commands/makemessages.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from re import Pattern
from re import Match, Pattern
from typing import Any

from django.core.management.base import BaseCommand
Expand All @@ -9,6 +9,7 @@ STATUS_OK: int
NO_LOCALE_DIR: Any

def check_programs(*programs: str) -> None: ...
def is_valid_locale(locale: str) -> Match[str] | None: ...

class TranslatableFile:
dirpath: str
Expand All @@ -21,6 +22,9 @@ class BuildFile:
Represent the state of a translatable file during the build process.
"""

command: BaseCommand
domain: str
translatable: TranslatableFile
def __init__(self, command: BaseCommand, domain: str, translatable: TranslatableFile) -> None: ...
@cached_property
def is_templatized(self) -> bool: ...
Expand All @@ -42,3 +46,25 @@ class Command(BaseCommand):
msguniq_options: list[str]
msgattrib_options: list[str]
xgettext_options: list[str]

domain: str
verbosity: int
symlinks: bool
ignore_patterns: list[str]
no_obsolete: bool
keep_pot: bool
extensions: set[str]
invoked_for_django: bool
locale_paths: list[str]
default_locale_path: str | None
@cached_property
def gettext_version(self) -> tuple[int, int] | tuple[int, int, int]: ...
@cached_property
def settings_available(self) -> bool: ...
def build_potfiles(self) -> list[str]: ...
def remove_potfiles(self) -> None: ...
def find_files(self, root: str) -> list[TranslatableFile]: ...
def process_files(self, file_list: list[TranslatableFile]) -> None: ...
def process_locale_dir(self, locale_dir: str, files: list[TranslatableFile]) -> None: ...
def write_po_file(self, potfile: str, locale: str) -> None: ...
def copy_plural_forms(self, msgs: str, locale: str) -> str: ...
4 changes: 4 additions & 0 deletions django-stubs/core/management/commands/runserver.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from re import Pattern
from typing import Any

from django.core.handlers.wsgi import WSGIHandler
from django.core.management.base import BaseCommand
from django.core.servers.basehttp import WSGIServer

naiveip_re: Pattern[str]

class Command(BaseCommand):
default_addr: str
default_addr_ipv6: str
Expand All @@ -13,3 +16,4 @@ class Command(BaseCommand):
def run(self, **options: Any) -> None: ...
def get_handler(self, *args: Any, **options: Any) -> WSGIHandler: ...
def inner_run(self, *args: Any, **options: Any) -> None: ...
def on_bind(self, server_port: int) -> None: ...
2 changes: 2 additions & 0 deletions django-stubs/core/management/commands/shell.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ from django.core.management import BaseCommand

class Command(BaseCommand):
shells: list[str]

def handle(self, **options: Any) -> None: ...
def ipython(self, options: Any) -> None: ...
def bpython(self, options: Any) -> None: ...
def python(self, options: Any) -> None: ...
4 changes: 4 additions & 0 deletions django-stubs/core/management/commands/sqlflush.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import Any

from django.core.management.base import BaseCommand

class Command(BaseCommand):
output_transaction: bool

def handle(self, **options: Any) -> str: ...
4 changes: 4 additions & 0 deletions django-stubs/core/management/commands/squashmigrations.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from typing import Any

from django.core.management.base import BaseCommand
from django.db.migrations.loader import MigrationLoader
from django.db.migrations.migration import Migration

class Command(BaseCommand):
verbosity: int
interactive: bool

def handle(self, **options: Any) -> None: ...
def find_migration(self, loader: MigrationLoader, app_label: str, name: str) -> Migration: ...
4 changes: 4 additions & 0 deletions django-stubs/core/management/commands/startapp.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import Any

from django.core.management.templates import TemplateCommand

class Command(TemplateCommand):
missing_args_message: str

def handle(self, **options: Any) -> None: ... # type: ignore[override]
4 changes: 4 additions & 0 deletions django-stubs/core/management/commands/startproject.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import Any

from django.core.management.templates import TemplateCommand

class Command(TemplateCommand):
missing_args_message: str

def handle(self, **options: Any) -> None: ... # type: ignore[override]
4 changes: 4 additions & 0 deletions scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ django.core.validators.slug_re
django.core.validators.slug_unicode_re
django.core.validators.URLValidator.regex
django.core.management.commands.makemessages.plural_forms_re
django.core.management.commands.runserver.naiveip_re
django.http.request.host_validation_re
django.middleware.csrf.invalid_token_chars_re
django.template.base.filter_re
Expand Down Expand Up @@ -231,10 +232,13 @@ django.core.files.storage.memory.InMemoryStorage.file_permissions_mode
django.core.files.storage.memory.InMemoryStorage.location
django.core.handlers.asgi.ASGIRequest.COOKIES
django.core.handlers.asgi.ASGIRequest.GET
django.core.management.commands.loaddata.Command.compression_formats
django.core.management.commands.loaddata.Command.fixture_dirs
django.core.management.commands.makemessages.BuildFile.is_templatized
django.core.management.commands.makemessages.BuildFile.path
django.core.management.commands.makemessages.BuildFile.work_path
django.core.management.commands.makemessages.Command.gettext_version
django.core.management.commands.makemessages.Command.settings_available
django.core.paginator.Paginator.count
django.core.paginator.Paginator.num_pages
django.db.backends.base.base.BaseDatabaseWrapper.timezone
Expand Down
38 changes: 0 additions & 38 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ django.contrib.contenttypes.admin.GenericTabularInline
django.contrib.contenttypes.fields.GenericRelation.contribute_to_class
django.contrib.contenttypes.fields.GenericRelation.get_extra_restriction
django.contrib.contenttypes.forms.generic_inlineformset_factory
django.contrib.contenttypes.management.commands.remove_stale_contenttypes.Command.handle
django.contrib.contenttypes.management.inject_rename_contenttypes_operations
django.contrib.contenttypes.models.ContentType.app_label
django.contrib.contenttypes.models.ContentType.app_labeled_name
Expand Down Expand Up @@ -710,7 +709,6 @@ django.contrib.sessions.base_session.AbstractBaseSession.get_previous_by_expire_
django.contrib.sessions.base_session.AbstractBaseSession.session_data
django.contrib.sessions.base_session.AbstractBaseSession.session_key
django.contrib.sessions.base_session.BaseSessionManager.__slotnames__
django.contrib.sessions.management.commands.clearsessions.Command.handle
django.contrib.sessions.models.Session.expire_date
django.contrib.sessions.models.Session.get_next_by_expire_date
django.contrib.sessions.models.Session.get_previous_by_expire_date
Expand Down Expand Up @@ -776,47 +774,11 @@ django.core.mail.make_msgid
django.core.mail.message.SafeMIMEMultipart.__init__
django.core.mail.message.SafeMIMEText.__init__
django.core.mail.outbox
django.core.management.BaseCommand.add_base_argument
django.core.management.BaseCommand.suppressed_base_arguments
django.core.management.base.ALL_CHECKS
django.core.management.base.BaseCommand.add_base_argument
django.core.management.base.BaseCommand.suppressed_base_arguments
django.core.management.commands.compilemessages.Command.handle
django.core.management.commands.dbshell.Command.handle
django.core.management.commands.diffsettings.Command.handle
django.core.management.commands.flush.Command.handle
django.core.management.commands.flush.Command.stealth_options
django.core.management.commands.inspectdb.Command.get_meta
django.core.management.commands.inspectdb.Command.handle
django.core.management.commands.loaddata.Command.compression_formats
django.core.management.commands.loaddata.Command.find_fixture_files_in_dir
django.core.management.commands.loaddata.Command.get_fixture_name_and_dirs
django.core.management.commands.loaddata.Command.get_targets
django.core.management.commands.loaddata.Command.reset_sequences
django.core.management.commands.loaddata.Command.save_obj
django.core.management.commands.makemessages.Command.build_potfiles
django.core.management.commands.makemessages.Command.copy_plural_forms
django.core.management.commands.makemessages.Command.find_files
django.core.management.commands.makemessages.Command.gettext_version
django.core.management.commands.makemessages.Command.process_files
django.core.management.commands.makemessages.Command.process_locale_dir
django.core.management.commands.makemessages.Command.remove_potfiles
django.core.management.commands.makemessages.Command.settings_available
django.core.management.commands.makemessages.Command.write_po_file
django.core.management.commands.makemessages.TranslatableFile.__ge__
django.core.management.commands.makemessages.TranslatableFile.__gt__
django.core.management.commands.makemessages.TranslatableFile.__le__
django.core.management.commands.makemessages.TranslatableFile.__lt__
django.core.management.commands.makemessages.TranslatableFile.path
django.core.management.commands.makemessages.is_valid_locale
django.core.management.commands.runserver.Command.on_bind
django.core.management.commands.runserver.Command.suppressed_base_arguments
django.core.management.commands.runserver.naiveip_re
django.core.management.commands.shell.Command.handle
django.core.management.commands.sqlflush.Command.handle
django.core.management.commands.squashmigrations.Command.handle
django.core.management.commands.startapp.Command.handle
django.core.management.commands.startproject.Command.handle
django.core.management.utils.find_formatters
django.core.management.utils.run_formatters
django.core.management.utils.sentinel
Expand Down

0 comments on commit 5d54ac4

Please sign in to comment.