Skip to content

Commit

Permalink
Introduce flake8-pyi in pre-commit checks (#1253)
Browse files Browse the repository at this point in the history
* only allow redirect_chain attribute in response when client sets the follow flag

Signed-off-by: Oleg Hoefling <[email protected]>

* compat for py3.7

Signed-off-by: Oleg Hoefling <[email protected]>

* compat for py3.7, fixed

Signed-off-by: Oleg Hoefling <[email protected]>

* address review comments, extract follow flag checks in a separate test case

Signed-off-by: Oleg Hoefling <[email protected]>

* configure flake8-pyi plugin in pre-commit

Signed-off-by: Oleg Hoefling <[email protected]>

* use pep 604 union types where possible

Signed-off-by: Oleg Hoefling <[email protected]>

* fix Y015

Signed-off-by: Oleg Hoefling <[email protected]>

* use PEP 585 container types where possible, replace obsolete typing types with collections.abc

Signed-off-by: Oleg Hoefling <[email protected]>

* allow isort to reorder non-top imports

Signed-off-by: Oleg Hoefling <[email protected]>

* finish PEP 585 changes, use PEP 613 where possible

Signed-off-by: Oleg Hoefling <[email protected]>

* fix remaining flake8-pyi warnings, silence warnings in question

Signed-off-by: Oleg Hoefling <[email protected]>

* fix Y023

Signed-off-by: Oleg Hoefling <[email protected]>

* fix Y029

Signed-off-by: Oleg Hoefling <[email protected]>

Signed-off-by: Oleg Hoefling <[email protected]>
  • Loading branch information
hoefling authored Nov 13, 2022
1 parent 1b8c1b5 commit b81b1bf
Show file tree
Hide file tree
Showing 489 changed files with 7,690 additions and 7,698 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ repos:
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
- flake8-pyi
types: []
files: ^.*.pyi?$

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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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: ...
Loading

0 comments on commit b81b1bf

Please sign in to comment.