Skip to content

Commit 2b53fa5

Browse files
mkurnikovblueyed
andauthored
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 <[email protected]>
1 parent e3ea841 commit 2b53fa5

File tree

5 files changed

+21
-34
lines changed

5 files changed

+21
-34
lines changed

django-sources

Submodule django-sources updated 63 files

django-stubs/db/models/options.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Options(Generic[_M]):
5151
verbose_name: Optional[str] = ...
5252
verbose_name_plural: Optional[str] = ...
5353
db_table: str = ...
54-
ordering: Optional[List[str]] = ...
54+
ordering: Optional[Sequence[str]] = ...
5555
indexes: List[Any] = ...
5656
unique_together: Union[List[Any], Tuple] = ...
5757
index_together: Union[List[Any], Tuple] = ...

mypy_django_plugin/transformers/models.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from collections import OrderedDict
2-
from typing import Type, cast
2+
from typing import Type
33

44
from django.db.models.base import Model
55
from django.db.models.fields import DateField, DateTimeField
66
from django.db.models.fields.related import ForeignKey
77
from django.db.models.fields.reverse_related import (
88
ManyToManyRel, ManyToOneRel, OneToOneRel,
99
)
10-
from mypy.newsemanal.semanal import NewSemanticAnalyzer
1110
from mypy.nodes import (
1211
ARG_STAR2, MDEF, Argument, SymbolTableNode, TypeInfo, Var,
1312
)
@@ -23,7 +22,7 @@
2322

2423
class ModelClassInitializer:
2524
def __init__(self, ctx: ClassDefContext, django_context: DjangoContext):
26-
self.api = cast(NewSemanticAnalyzer, ctx.api)
25+
self.api = ctx.api
2726
self.model_classdef = ctx.cls
2827
self.django_context = django_context
2928
self.ctx = ctx

scripts/enabled_test_modules.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
'__new_common__': [
1919
*MOCK_OBJECTS,
2020
*EXTERNAL_MODULES,
21-
'SupportsFloat',
2221
'Need type annotation for',
2322
'has no attribute "getvalue"',
2423
'Cannot assign to a method',
2524
'Cannot infer type of lambda',
26-
'already defined (possibly by an import)',
27-
'already defined on line',
25+
'already defined',
2826
'Cannot assign to a type',
2927
'"HttpResponse" has no attribute',
3028
'"HttpResponseBase" has no attribute',
@@ -53,7 +51,6 @@
5351
"No installed app with label 'missing'",
5452
'namedtuple',
5553
'Lookups not supported yet',
56-
'Argument 1 to "loads" has incompatible type',
5754
# TODO: see test in managers/test_managers.yml
5855
"Cannot determine type of",
5956
'cache_clear',
@@ -63,7 +60,6 @@
6360
# TODO: not supported yet
6461
'GenericRelation',
6562
'RelatedObjectDoesNotExist',
66-
# Rel's attributes are not accessible from `get_field()`
6763
re.compile(r'"Field\[Any, Any\]" has no attribute '
6864
r'"(through|field_name|field|get_related_field|related_model|related_name'
6965
r'|get_accessor_name|empty_strings_allowed|many_to_many)"'),

scripts/typecheck_tests.py

+16-24
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ def replace_with_clickable_location(error: str, abs_test_folder: Path) -> str:
5151

5252
try:
5353
mypy_options = ['--cache-dir', str(mypy_config_file.parent / '.mypy_cache'),
54-
'--config-file', str(mypy_config_file)]
54+
'--config-file', str(mypy_config_file),
55+
'--show-traceback',
56+
# '--no-error-summary',
57+
# '--no-pretty',
58+
'--hide-error-context'
59+
]
5560
mypy_options += [str(tests_root)]
5661

5762
import distutils.spawn
@@ -62,34 +67,21 @@ def replace_with_clickable_location(error: str, abs_test_folder: Path) -> str:
6267
mypy_argv,
6368
env={'PYTHONPATH': str(tests_root)},
6469
stdout=subprocess.PIPE,
65-
stderr=subprocess.PIPE,
70+
stderr=subprocess.STDOUT,
6671
)
67-
rc = completed.returncode
68-
stdout = completed.stdout.decode()
69-
stderr = completed.stderr.decode()
70-
if rc not in (0, 1) or stderr:
71-
import shlex
72-
73-
cmd = " ".join(shlex.quote(s) for s in mypy_argv)
74-
print("Failed to run {} (exitcode {})!".format(cmd, rc), file=sys.stderr)
75-
if stderr:
76-
print("=== Output on stderr: ===\n{}".format(stderr.rstrip("\n")))
77-
if stdout:
78-
print("=== Output on stdout: ===\n{}".format(stdout.rstrip("\n")))
79-
sys.exit(rc or 1)
80-
81-
sorted_lines = sorted(stdout.splitlines())
72+
output = completed.stdout.decode()
73+
74+
sorted_lines = sorted(output.splitlines())
8275
for line in sorted_lines:
8376
try:
84-
module_name = line.split('/')[0]
77+
path_to_error = line.split(':')[0]
78+
test_folder_name = path_to_error.split('/')[2]
8579
except IndexError:
86-
module_name = 'unknown'
80+
test_folder_name = 'unknown'
8781

88-
if not is_ignored(line, module_name):
89-
if line.startswith(module_name):
90-
print(replace_with_clickable_location(line, abs_test_folder=tests_root))
91-
else:
92-
print(line)
82+
if not is_ignored(line, test_folder_name):
83+
global_rc = 1
84+
print(line)
9385

9486
sys.exit(global_rc)
9587

0 commit comments

Comments
 (0)