diff --git a/src/whitenoise/runserver_nostatic/management/commands/runserver.py b/src/whitenoise/runserver_nostatic/management/commands/runserver.py index 484b1442..83f0f65f 100644 --- a/src/whitenoise/runserver_nostatic/management/commands/runserver.py +++ b/src/whitenoise/runserver_nostatic/management/commands/runserver.py @@ -8,24 +8,29 @@ """ from __future__ import annotations +import argparse from importlib import import_module +from typing import Generator from django.apps import apps +from django.core.management import BaseCommand -def get_next_runserver_command(): +def get_next_runserver_command() -> type[BaseCommand]: """ Return the next highest priority "runserver" command class """ for app_name in get_lower_priority_apps(): module_path = "%s.management.commands.runserver" % app_name try: - return import_module(module_path).Command + klass: type[BaseCommand] = import_module(module_path).Command + return klass except (ImportError, AttributeError): pass + raise ValueError("No lower priority app has a 'runserver' command") -def get_lower_priority_apps(): +def get_lower_priority_apps() -> Generator[str, None, None]: """ Yield all app module names below the current app in the INSTALLED_APPS list """ @@ -42,11 +47,12 @@ def get_lower_priority_apps(): RunserverCommand = get_next_runserver_command() -class Command(RunserverCommand): - def add_arguments(self, parser): +class Command(RunserverCommand): # type: ignore [misc,valid-type] + def add_arguments(self, parser: argparse.ArgumentParser) -> None: super().add_arguments(parser) if parser.get_default("use_static_handler") is True: parser.set_defaults(use_static_handler=False) + assert parser.description is not None parser.description += ( "\n(Wrapped by 'whitenoise.runserver_nostatic' to always" " enable '--nostatic')"