Skip to content
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

Introduce flake8-pyi in pre-commit checks #1253

Merged
merged 13 commits into from Nov 13, 2022
Merged
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -33,6 +33,10 @@ repos:
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
- flake8-pyi
types: []
files: ^.*.pyi?$
Comment on lines 35 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has stopped flake8 from running on the repo’s Python files, so we need two configurations. Also, please pin the version of flake8-pyi so there are no surprise failures when a new version is released.

Suggested change
- id: flake8
additional_dependencies:
- flake8-pyi
types: []
files: ^.*.pyi?$
- id: flake8
- id: flake8
additional_dependencies:
- flake8-pyi==22.10.0
types: []
files: ^.*.pyi?$

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamchainz the glob includes .py files (note the trailing question mark), so the flake8 hook will run on both .py and .pyi files. I can introduce a second hook if you want tho 😎

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, missed that! No need for a second hook, I think, unless flake8-pyi rules will be problematic for plain python files.


ci:
autofix_commit_msg: '[pre-commit.ci] auto fixes from pre-commit.com hooks'
Expand Down
24 changes: 12 additions & 12 deletions django-stubs/apps/config.pyi
@@ -1,5 +1,5 @@
import types
from typing import Dict, Iterator, Optional, Type
from collections.abc import Iterator

from django.apps.registry import Apps
from django.db.models.base import Model
Expand All @@ -8,18 +8,18 @@ from django.utils.functional import _StrOrPromise
MODELS_MODULE_NAME: str

class AppConfig:
name: str = ...
module: Optional[types.ModuleType] = ...
apps: Optional[Apps] = ...
label: str = ...
verbose_name: _StrOrPromise = ...
path: str = ...
models_module: Optional[str] = ...
models: Dict[str, Type[Model]] = ...
def __init__(self, app_name: str, app_module: Optional[types.ModuleType]) -> None: ...
name: str
module: types.ModuleType | None
apps: Apps | None
label: str
verbose_name: _StrOrPromise
path: str
models_module: str | None
models: dict[str, type[Model]]
def __init__(self, app_name: str, app_module: types.ModuleType | None) -> None: ...
@classmethod
def create(cls, entry: str) -> AppConfig: ...
def get_model(self, model_name: str, require_ready: bool = ...) -> Type[Model]: ...
def get_models(self, include_auto_created: bool = ..., include_swapped: bool = ...) -> Iterator[Type[Model]]: ...
def get_model(self, model_name: str, require_ready: bool = ...) -> type[Model]: ...
def get_models(self, include_auto_created: bool = ..., include_swapped: bool = ...) -> Iterator[type[Model]]: ...
def import_models(self) -> None: ...
def ready(self) -> None: ...
39 changes: 20 additions & 19 deletions django-stubs/apps/registry.pyi
@@ -1,40 +1,41 @@
import threading
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union
from collections.abc import Callable, Iterable
from typing import Any

from django.db.models.base import Model

from .config import AppConfig

class Apps:
all_models: Dict[str, Dict[str, Type[Model]]] = ...
app_configs: Dict[str, AppConfig] = ...
stored_app_configs: List[Any] = ...
apps_ready: bool = ...
ready_event: threading.Event = ...
loading: bool = ...
_pending_operations: Dict[Tuple[str, str], List]
models_ready: bool = ...
ready: bool = ...
def __init__(self, installed_apps: Optional[Iterable[Union[AppConfig, str]]] = ...) -> None: ...
def populate(self, installed_apps: Iterable[Union[AppConfig, str]] = ...) -> None: ...
all_models: dict[str, dict[str, type[Model]]]
app_configs: dict[str, AppConfig]
stored_app_configs: list[Any]
apps_ready: bool
ready_event: threading.Event
loading: bool
_pending_operations: dict[tuple[str, str], list]
models_ready: bool
ready: bool
def __init__(self, installed_apps: Iterable[AppConfig | str] | None = ...) -> None: ...
def populate(self, installed_apps: Iterable[AppConfig | str] = ...) -> None: ...
def check_apps_ready(self) -> None: ...
def check_models_ready(self) -> None: ...
def get_app_configs(self) -> Iterable[AppConfig]: ...
def get_app_config(self, app_label: str) -> AppConfig: ...
# it's not possible to support it in plugin properly now
def get_models(self, include_auto_created: bool = ..., include_swapped: bool = ...) -> List[Type[Model]]: ...
def get_model(self, app_label: str, model_name: Optional[str] = ..., require_ready: bool = ...) -> Type[Any]: ...
def register_model(self, app_label: str, model: Type[Model]) -> None: ...
def get_models(self, include_auto_created: bool = ..., include_swapped: bool = ...) -> list[type[Model]]: ...
def get_model(self, app_label: str, model_name: str | None = ..., require_ready: bool = ...) -> type[Any]: ...
def register_model(self, app_label: str, model: type[Model]) -> None: ...
def is_installed(self, app_name: str) -> bool: ...
def get_containing_app_config(self, object_name: str) -> Optional[AppConfig]: ...
def get_registered_model(self, app_label: str, model_name: str) -> Type[Model]: ...
def get_swappable_settings_name(self, to_string: str) -> Optional[str]: ...
def get_containing_app_config(self, object_name: str) -> AppConfig | None: ...
def get_registered_model(self, app_label: str, model_name: str) -> type[Model]: ...
def get_swappable_settings_name(self, to_string: str) -> str | None: ...
def set_available_apps(self, available: Iterable[str]) -> None: ...
def unset_available_apps(self) -> None: ...
def set_installed_apps(self, installed: Iterable[str]) -> None: ...
def unset_installed_apps(self) -> None: ...
def clear_cache(self) -> None: ...
def lazy_model_operation(self, function: Callable, *model_keys: Any) -> None: ...
def do_pending_operations(self, model: Type[Model]) -> None: ...
def do_pending_operations(self, model: type[Model]) -> None: ...

apps: Apps
15 changes: 8 additions & 7 deletions django-stubs/conf/__init__.pyi
@@ -1,13 +1,14 @@
from typing import Any, Optional
from typing import Any

from _typeshed import Self
from django.utils.functional import LazyObject

# explicit dependency on standard settings to make it loaded
from . import global_settings

ENVIRONMENT_VARIABLE: str = ...
PASSWORD_RESET_TIMEOUT_DAYS_DEPRECATED_MSG: str = ...
DEFAULT_HASHING_ALGORITHM_DEPRECATED_MSG: str = ...
ENVIRONMENT_VARIABLE: str
PASSWORD_RESET_TIMEOUT_DAYS_DEPRECATED_MSG: str
DEFAULT_HASHING_ALGORITHM_DEPRECATED_MSG: str

# required for plugin to be able to distinguish this specific instance of LazySettings from others
class _DjangoConfLazyObject(LazyObject):
Expand All @@ -19,21 +20,21 @@ class LazySettings(_DjangoConfLazyObject):
def configured(self) -> bool: ...
def configure(self, default_settings: Any = ..., **options: Any) -> None: ...

settings: LazySettings = ...
settings: LazySettings

class Settings:
SETTINGS_MODULE: str
def __init__(self, settings_module: str) -> None: ...
def is_overridden(self, setting: str) -> bool: ...

class UserSettingsHolder:
SETTINGS_MODULE: None = ...
SETTINGS_MODULE: None
def __init__(self, default_settings: Any) -> None: ...
def __getattr__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __delattr__(self, name: str) -> None: ...
def is_overridden(self, setting: str) -> bool: ...

class SettingsReference(str):
def __new__(self, value: Any, setting_name: str) -> SettingsReference: ...
def __new__(self: type[Self], value: Any, setting_name: str) -> Self: ...
def __init__(self, value: str, setting_name: str) -> None: ...