Skip to content

Commit 5d54ac4

Browse files
Update django.core.management.commands.* (#1829)
* 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
1 parent 53cdbe4 commit 5d54ac4

File tree

18 files changed

+106
-47
lines changed

18 files changed

+106
-47
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from typing import Literal
1+
from typing import Any, Literal
22

33
from _typeshed import Unused
44
from django.core.management import BaseCommand
55
from django.db.models.deletion import Collector
66

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

910
class NoFastDeleteCollector(Collector):
1011
def can_fast_delete(self, *args: Unused, **kwargs: Unused) -> Literal[False]: ...
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Any
2+
13
from django.core.management.base import BaseCommand
24

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

django-stubs/core/management/base.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ from django.apps.config import AppConfig
77
from django.core.management.color import Style
88
from django.utils.datastructures import _ListOrTuple
99

10+
ALL_CHECKS: Literal["__all__"]
11+
1012
class CommandError(Exception):
1113
def __init__(self, *args: Any, returncode: int = ..., **kwargs: Any) -> None: ...
1214

@@ -49,6 +51,7 @@ class BaseCommand:
4951
requires_system_checks: _ListOrTuple[str] | Literal["__all__"]
5052
base_stealth_options: tuple[str, ...]
5153
stealth_options: tuple[str, ...]
54+
suppressed_base_arguments: set[str]
5255
stdout: OutputWrapper
5356
stderr: OutputWrapper
5457
style: Style
@@ -62,6 +65,7 @@ class BaseCommand:
6265
def get_version(self) -> str: ...
6366
def create_parser(self, prog_name: str, subcommand: str, **kwargs: Any) -> CommandParser: ...
6467
def add_arguments(self, parser: CommandParser) -> None: ...
68+
def add_base_argument(self, parser: CommandParser, *args: Any, **kwargs: Any) -> None: ...
6569
def print_help(self, prog_name: str, subcommand: str) -> None: ...
6670
def run_from_argv(self, argv: list[str]) -> None: ...
6771
def execute(self, *args: Any, **options: Any) -> str | None: ...

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
from typing import Any
23

34
from django.core.management.base import BaseCommand
45
from django.utils._os import _PathCompatible
@@ -11,4 +12,5 @@ class Command(BaseCommand):
1112
program_options: list[str]
1213
verbosity: int
1314
has_errors: bool
15+
def handle(self, **options: Any) -> None: ...
1416
def compile_messages(self, locations: list[tuple[_PathCompatible, _PathCompatible]]) -> None: ...
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Any
2+
13
from django.core.management.base import BaseCommand
24

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand
66
def module_to_dict(module: Any, omittable: Callable[[str], bool] = ...) -> dict[str, str]: ...
77

88
class Command(BaseCommand):
9+
def handle(self, **options: Any) -> str: ...
910
def output_hash(
1011
self, user_settings: dict[str, str], default_settings: dict[str, str], **options: Any
1112
) -> list[str]: ...
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from typing import Any
2+
13
from django.core.management.base import BaseCommand
24
from django.core.management.color import Style
35

46
class Command(BaseCommand):
5-
stealth_options: tuple[str]
67
style: Style
8+
9+
def handle(self, **options: Any) -> None: ...

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ from django.core.management.base import BaseCommand
55
from django.db.backends.base.base import BaseDatabaseWrapper
66

77
class Command(BaseCommand):
8-
stealth_options: tuple[str]
98
db_module: str
9+
10+
def handle(self, **options: Any) -> None: ...
1011
def handle_inspection(self, options: dict[str, Any]) -> Iterable[str]: ...
1112
def normalize_col_name(
1213
self, col_name: str, used_column_names: list[str], is_relation: bool
@@ -15,5 +16,11 @@ class Command(BaseCommand):
1516
self, connection: BaseDatabaseWrapper, table_name: str, row: Any
1617
) -> tuple[str, dict[str, Any], list[str]]: ...
1718
def get_meta(
18-
self, table_name: str, constraints: Any, column_to_field_name: Any, is_view: Any, is_partition: Any
19+
self,
20+
table_name: str,
21+
constraints: Any,
22+
column_to_field_name: Any,
23+
is_view: bool,
24+
is_partition: bool,
25+
comment: str | None,
1926
) -> list[str]: ...

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
11
import zipfile
22
from collections.abc import Sequence
3+
from io import BufferedReader
4+
from typing import Callable, Literal
35

46
from django.apps.config import AppConfig
57
from django.core.management.base import BaseCommand
8+
from django.core.serializers.base import DeserializedObject
9+
from django.db.backends.base.base import BaseDatabaseWrapper
610
from django.db.models.base import Model
711
from django.utils.functional import cached_property
12+
from typing_extensions import TypeAlias
813

914
has_bz2: bool
1015
has_lzma: bool
1116

1217
READ_STDIN: str
18+
_ReadBinaryMode: TypeAlias = Literal["r", "rb"]
1319

1420
class Command(BaseCommand):
21+
missing_args_message: str
1522
ignore: bool
1623
using: str
1724
app_label: str
1825
verbosity: int
1926
excluded_models: set[type[Model]]
2027
excluded_apps: set[AppConfig]
2128
format: str
22-
missing_args_message: str
29+
fixture_count: int
30+
loaded_object_count: int
31+
fixture_object_count: int
32+
models: set[type[Model]]
33+
serialization_formats: list[str]
34+
objs_with_deferred_fields: list[DeserializedObject]
35+
@cached_property
36+
def compression_formats(self) -> dict[str | None, tuple[Callable[[str, _ReadBinaryMode], BufferedReader]]]: ...
37+
def reset_sequences(self, connection: BaseDatabaseWrapper, models: set[type[Model]]) -> None: ...
2338
def loaddata(self, fixture_labels: Sequence[str]) -> None: ...
39+
def save_obj(self, obj: DeserializedObject) -> bool: ...
2440
def load_label(self, fixture_label: str) -> None: ...
41+
def get_fixture_name_and_dirs(self, fixture_name: str) -> tuple[str, list[str]]: ...
42+
def get_targets(self, fixture_name: str, ser_fmt: str | None, cmp_fmt: str | None) -> set[str]: ...
43+
def find_fixture_files_in_dir(
44+
self, fixture_dir: str, fixture_name: str, targets: set[str]
45+
) -> list[tuple[str, str, str]]: ...
2546
def find_fixtures(self, fixture_label: str) -> list[tuple[str, str | None, str | None]]: ...
2647
@cached_property
2748
def fixture_dirs(self) -> list[str]: ...

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from re import Pattern
1+
from re import Match, Pattern
22
from typing import Any
33

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

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

1314
class TranslatableFile:
1415
dirpath: str
@@ -21,6 +22,9 @@ class BuildFile:
2122
Represent the state of a translatable file during the build process.
2223
"""
2324

25+
command: BaseCommand
26+
domain: str
27+
translatable: TranslatableFile
2428
def __init__(self, command: BaseCommand, domain: str, translatable: TranslatableFile) -> None: ...
2529
@cached_property
2630
def is_templatized(self) -> bool: ...
@@ -42,3 +46,25 @@ class Command(BaseCommand):
4246
msguniq_options: list[str]
4347
msgattrib_options: list[str]
4448
xgettext_options: list[str]
49+
50+
domain: str
51+
verbosity: int
52+
symlinks: bool
53+
ignore_patterns: list[str]
54+
no_obsolete: bool
55+
keep_pot: bool
56+
extensions: set[str]
57+
invoked_for_django: bool
58+
locale_paths: list[str]
59+
default_locale_path: str | None
60+
@cached_property
61+
def gettext_version(self) -> tuple[int, int] | tuple[int, int, int]: ...
62+
@cached_property
63+
def settings_available(self) -> bool: ...
64+
def build_potfiles(self) -> list[str]: ...
65+
def remove_potfiles(self) -> None: ...
66+
def find_files(self, root: str) -> list[TranslatableFile]: ...
67+
def process_files(self, file_list: list[TranslatableFile]) -> None: ...
68+
def process_locale_dir(self, locale_dir: str, files: list[TranslatableFile]) -> None: ...
69+
def write_po_file(self, potfile: str, locale: str) -> None: ...
70+
def copy_plural_forms(self, msgs: str, locale: str) -> str: ...

0 commit comments

Comments
 (0)