mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 04:54:48 +08:00
disable globbing for tests folders, add regex support for ignored errors
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Pattern
|
||||||
|
|
||||||
from git import Repo
|
from git import Repo
|
||||||
from mypy import build
|
from mypy import build
|
||||||
@@ -19,13 +20,13 @@ IGNORED_ERROR_PATTERNS = [
|
|||||||
'LazySettings',
|
'LazySettings',
|
||||||
'Cannot infer type of lambda',
|
'Cannot infer type of lambda',
|
||||||
'Incompatible types in assignment (expression has type "Callable[',
|
'Incompatible types in assignment (expression has type "Callable[',
|
||||||
'"Callable[[Any], Any]" has no attribute',
|
|
||||||
'"Callable[[Any, Any], Any]" has no attribute',
|
|
||||||
'Invalid value for a to= parameter',
|
'Invalid value for a to= parameter',
|
||||||
'"HttpResponseBase" has no attribute "user"'
|
re.compile(r'"Callable\[\[(Any(, )?)+\], Any\]" has no attribute'),
|
||||||
|
re.compile(r'"HttpResponseBase" has no attribute "[A-Za-z_]+"'),
|
||||||
]
|
]
|
||||||
TESTS_DIRS = [
|
TESTS_DIRS = [
|
||||||
'absolute_url_overrides',
|
'absolute_url_overrides',
|
||||||
|
'admin_autodiscover'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -46,6 +47,10 @@ def cd(path):
|
|||||||
|
|
||||||
def is_ignored(line: str) -> bool:
|
def is_ignored(line: str) -> bool:
|
||||||
for pattern in IGNORED_ERROR_PATTERNS:
|
for pattern in IGNORED_ERROR_PATTERNS:
|
||||||
|
if isinstance(pattern, Pattern):
|
||||||
|
if pattern.search(line):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
if pattern in line:
|
if pattern in line:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@@ -79,11 +84,9 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
repo.git.checkout(DJANGO_COMMIT_SHA)
|
repo.git.checkout(DJANGO_COMMIT_SHA)
|
||||||
for dirname in TESTS_DIRS:
|
for dirname in TESTS_DIRS:
|
||||||
paths = glob.glob(str(tests_root / dirname))
|
abs_path = (project_directory / tests_root / dirname).absolute()
|
||||||
for path in paths:
|
|
||||||
abs_path = (project_directory / path).absolute()
|
|
||||||
|
|
||||||
print(f'Checking {abs_path.as_uri()}')
|
print(f'Checking {abs_path.as_uri()}')
|
||||||
|
|
||||||
rc = check_with_mypy(abs_path, mypy_config_file)
|
rc = check_with_mypy(abs_path, mypy_config_file)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
global_rc = 1
|
global_rc = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user