mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-07 04:34:29 +08:00
Fix typecheck tests ci (#165)
* remove mention of mypy newsemanal to prepare for 0.730 * make typecheck_tests CI really work * fix lints * fix intentional error * merge stderr in stdout to preserve order Co-authored-by: Daniel Hahler <github@thequod.de>
This commit is contained in:
Submodule django-sources updated: 4d6449e125...f452d4232e
@@ -51,7 +51,7 @@ class Options(Generic[_M]):
|
||||
verbose_name: Optional[str] = ...
|
||||
verbose_name_plural: Optional[str] = ...
|
||||
db_table: str = ...
|
||||
ordering: Optional[List[str]] = ...
|
||||
ordering: Optional[Sequence[str]] = ...
|
||||
indexes: List[Any] = ...
|
||||
unique_together: Union[List[Any], Tuple] = ...
|
||||
index_together: Union[List[Any], Tuple] = ...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from collections import OrderedDict
|
||||
from typing import Type, cast
|
||||
from typing import Type
|
||||
|
||||
from django.db.models.base import Model
|
||||
from django.db.models.fields import DateField, DateTimeField
|
||||
@@ -7,7 +7,6 @@ from django.db.models.fields.related import ForeignKey
|
||||
from django.db.models.fields.reverse_related import (
|
||||
ManyToManyRel, ManyToOneRel, OneToOneRel,
|
||||
)
|
||||
from mypy.newsemanal.semanal import NewSemanticAnalyzer
|
||||
from mypy.nodes import (
|
||||
ARG_STAR2, MDEF, Argument, SymbolTableNode, TypeInfo, Var,
|
||||
)
|
||||
@@ -23,7 +22,7 @@ from mypy_django_plugin.transformers.fields import get_field_descriptor_types
|
||||
|
||||
class ModelClassInitializer:
|
||||
def __init__(self, ctx: ClassDefContext, django_context: DjangoContext):
|
||||
self.api = cast(NewSemanticAnalyzer, ctx.api)
|
||||
self.api = ctx.api
|
||||
self.model_classdef = ctx.cls
|
||||
self.django_context = django_context
|
||||
self.ctx = ctx
|
||||
|
||||
@@ -18,13 +18,11 @@ IGNORED_ERRORS = {
|
||||
'__new_common__': [
|
||||
*MOCK_OBJECTS,
|
||||
*EXTERNAL_MODULES,
|
||||
'SupportsFloat',
|
||||
'Need type annotation for',
|
||||
'has no attribute "getvalue"',
|
||||
'Cannot assign to a method',
|
||||
'Cannot infer type of lambda',
|
||||
'already defined (possibly by an import)',
|
||||
'already defined on line',
|
||||
'already defined',
|
||||
'Cannot assign to a type',
|
||||
'"HttpResponse" has no attribute',
|
||||
'"HttpResponseBase" has no attribute',
|
||||
@@ -53,7 +51,6 @@ IGNORED_ERRORS = {
|
||||
"No installed app with label 'missing'",
|
||||
'namedtuple',
|
||||
'Lookups not supported yet',
|
||||
'Argument 1 to "loads" has incompatible type',
|
||||
# TODO: see test in managers/test_managers.yml
|
||||
"Cannot determine type of",
|
||||
'cache_clear',
|
||||
@@ -63,7 +60,6 @@ IGNORED_ERRORS = {
|
||||
# TODO: not supported yet
|
||||
'GenericRelation',
|
||||
'RelatedObjectDoesNotExist',
|
||||
# Rel's attributes are not accessible from `get_field()`
|
||||
re.compile(r'"Field\[Any, Any\]" has no attribute '
|
||||
r'"(through|field_name|field|get_related_field|related_model|related_name'
|
||||
r'|get_accessor_name|empty_strings_allowed|many_to_many)"'),
|
||||
|
||||
@@ -51,7 +51,12 @@ if __name__ == '__main__':
|
||||
|
||||
try:
|
||||
mypy_options = ['--cache-dir', str(mypy_config_file.parent / '.mypy_cache'),
|
||||
'--config-file', str(mypy_config_file)]
|
||||
'--config-file', str(mypy_config_file),
|
||||
'--show-traceback',
|
||||
# '--no-error-summary',
|
||||
# '--no-pretty',
|
||||
'--hide-error-context'
|
||||
]
|
||||
mypy_options += [str(tests_root)]
|
||||
|
||||
import distutils.spawn
|
||||
@@ -62,34 +67,21 @@ if __name__ == '__main__':
|
||||
mypy_argv,
|
||||
env={'PYTHONPATH': str(tests_root)},
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
rc = completed.returncode
|
||||
stdout = completed.stdout.decode()
|
||||
stderr = completed.stderr.decode()
|
||||
if rc not in (0, 1) or stderr:
|
||||
import shlex
|
||||
output = completed.stdout.decode()
|
||||
|
||||
cmd = " ".join(shlex.quote(s) for s in mypy_argv)
|
||||
print("Failed to run {} (exitcode {})!".format(cmd, rc), file=sys.stderr)
|
||||
if stderr:
|
||||
print("=== Output on stderr: ===\n{}".format(stderr.rstrip("\n")))
|
||||
if stdout:
|
||||
print("=== Output on stdout: ===\n{}".format(stdout.rstrip("\n")))
|
||||
sys.exit(rc or 1)
|
||||
|
||||
sorted_lines = sorted(stdout.splitlines())
|
||||
sorted_lines = sorted(output.splitlines())
|
||||
for line in sorted_lines:
|
||||
try:
|
||||
module_name = line.split('/')[0]
|
||||
path_to_error = line.split(':')[0]
|
||||
test_folder_name = path_to_error.split('/')[2]
|
||||
except IndexError:
|
||||
module_name = 'unknown'
|
||||
test_folder_name = 'unknown'
|
||||
|
||||
if not is_ignored(line, module_name):
|
||||
if line.startswith(module_name):
|
||||
print(replace_with_clickable_location(line, abs_test_folder=tests_root))
|
||||
else:
|
||||
print(line)
|
||||
if not is_ignored(line, test_folder_name):
|
||||
global_rc = 1
|
||||
print(line)
|
||||
|
||||
sys.exit(global_rc)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user