* Fix CI

* Fix CI

* Fix CI

* Fix CI

* APply black

* APply black

* Fix mypy

* Fix mypy errors in django-stubs

* Fix format

* Fix plugin

* Do not patch builtins by default

* Fix mypy

* Only run mypy on 3.10 for now

* Only run mypy on 3.10 for now

* WHAT THE HELL

* Enable strict mode in mypy

* Enable strict mode in mypy

* Fix tests

* Fix tests

* Debug

* Debug

* Fix tests

* Fix tests

* Add TYPE_CHECKING debug

* Caching maybe?

* Caching maybe?

* Try explicit `${{ matrix.python-version }}`

* Remove debug

* Fix typing

* Finally
This commit is contained in:
Nikita Sobolev
2022-08-26 13:22:55 +03:00
committed by GitHub
parent d2bfd3710b
commit 0bb1182c42
80 changed files with 223 additions and 582 deletions

View File

@@ -1,6 +1,7 @@
# Some errors occur for the test suite itself, and cannot be addressed via django-stubs. They should be ignored
# using this constant.
import re
from typing import Any, Dict, List
IGNORED_MODULES = {
"schema",
@@ -56,7 +57,7 @@ EXTERNAL_MODULES = [
"argon2",
"xml.dom",
]
IGNORED_ERRORS = {
IGNORED_ERRORS: Dict[str, List[Any]] = {
"__common__": [
*MOCK_OBJECTS,
*EXTERNAL_MODULES,

View File

@@ -1,7 +1,8 @@
import shutil
from typing import Optional
from typing import Optional, Union
from git import RemoteProgress, Repo
from git.remote import RemoteProgress
from git.repo import Repo
from scripts.paths import DJANGO_SOURCE_DIRECTORY
@@ -10,7 +11,9 @@ class ProgressPrinter(RemoteProgress):
def line_dropped(self, line: str) -> None:
print(line)
def update(self, op_code, cur_count, max_count=None, message=""):
def update(
self, op_code: int, cur_count: Union[str, float], max_count: Union[str, float, None] = None, message: str = ""
) -> None:
print(self._cur_line)
@@ -22,7 +25,7 @@ def checkout_django_branch(django_version: str, commit_sha: Optional[str]) -> Re
repo = Repo.clone_from(
"https://github.com/django/django.git",
DJANGO_SOURCE_DIRECTORY,
progress=ProgressPrinter(),
progress=ProgressPrinter(), # type: ignore
branch=branch,
depth=100,
)

View File

@@ -5,6 +5,7 @@ from pytest_mypy_plugins.item import YamlTestItem
def django_plugin_hook(test_item: YamlTestItem) -> None:
custom_settings = test_item.parsed_test_data.get("custom_settings", "")
installed_apps = test_item.parsed_test_data.get("installed_apps", None)
monkeypatch = test_item.parsed_test_data.get("monkeypatch", False)
if installed_apps and custom_settings:
raise ValueError('"installed_apps" and "custom_settings" are not compatible, please use one or the other')
@@ -18,6 +19,9 @@ def django_plugin_hook(test_item: YamlTestItem) -> None:
if "SECRET_KEY" not in custom_settings:
custom_settings = 'SECRET_KEY = "1"\n' + custom_settings
if monkeypatch:
custom_settings = "import django_stubs_ext\ndjango_stubs_ext.monkeypatch()\n" + custom_settings
django_settings_section = "\n[mypy.plugins.django-stubs]\n" "django_settings_module = mysettings"
if not test_item.additional_mypy_config:
test_item.additional_mypy_config = django_settings_section

View File

@@ -5,7 +5,7 @@ import sys
from argparse import ArgumentParser
from collections import defaultdict
from distutils import spawn
from typing import Dict, List, Pattern, Union
from typing import DefaultDict, List, Pattern, Union
from scripts.enabled_test_modules import EXTERNAL_MODULES, IGNORED_ERRORS, IGNORED_MODULES, MOCK_OBJECTS
from scripts.git_helpers import checkout_django_branch
@@ -18,8 +18,10 @@ DJANGO_COMMIT_REFS = {
}
DEFAULT_DJANGO_VERSION = "3.2"
_DictToSearch = DefaultDict[str, DefaultDict[Union[str, Pattern[str]], int]]
def get_unused_ignores(ignored_message_freq: Dict[str, Dict[Union[str, Pattern], int]]) -> List[str]:
def get_unused_ignores(ignored_message_freq: _DictToSearch) -> List[str]:
unused_ignores = []
for root_key, patterns in IGNORED_ERRORS.items():
for pattern in patterns:
@@ -30,7 +32,7 @@ def get_unused_ignores(ignored_message_freq: Dict[str, Dict[Union[str, Pattern],
return unused_ignores
def does_pattern_fit(pattern: Union[Pattern, str], line: str):
def does_pattern_fit(pattern: Union[Pattern[str], str], line: str) -> bool:
if isinstance(pattern, Pattern):
if pattern.search(line):
return True
@@ -40,7 +42,7 @@ def does_pattern_fit(pattern: Union[Pattern, str], line: str):
return False
def is_ignored(line: str, test_folder_name: str, *, ignored_message_freqs: Dict[str, Dict[str, int]]) -> bool:
def is_ignored(line: str, test_folder_name: str, *, ignored_message_freqs: _DictToSearch) -> bool:
if "runtests" in line:
return True
@@ -86,14 +88,14 @@ if __name__ == "__main__":
mypy_executable = spawn.find_executable("mypy")
mypy_argv = [mypy_executable, *mypy_options]
completed = subprocess.run(
mypy_argv,
mypy_argv, # type: ignore
env={"PYTHONPATH": str(tests_root), "TYPECHECK_TESTS": "1"},
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
output = completed.stdout.decode()
ignored_message_freqs = defaultdict(lambda: defaultdict(int))
ignored_message_freqs: _DictToSearch = defaultdict(lambda: defaultdict(int))
sorted_lines = sorted(output.splitlines())
for line in sorted_lines: