diff --git a/django-sources b/django-sources index 4d6449e..f452d42 160000 --- a/django-sources +++ b/django-sources @@ -1 +1 @@ -Subproject commit 4d6449e1258c88b6e4e1ccbb5e84b210371598d2 +Subproject commit f452d4232e1c14269bf2f1bd234d6e4ef462dc55 diff --git a/django-stubs/db/models/options.pyi b/django-stubs/db/models/options.pyi index 84a0607..14f1352 100644 --- a/django-stubs/db/models/options.pyi +++ b/django-stubs/db/models/options.pyi @@ -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] = ... diff --git a/mypy_django_plugin/transformers/models.py b/mypy_django_plugin/transformers/models.py index c1272d7..64ce2b5 100644 --- a/mypy_django_plugin/transformers/models.py +++ b/mypy_django_plugin/transformers/models.py @@ -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 diff --git a/scripts/enabled_test_modules.py b/scripts/enabled_test_modules.py index aad1c20..24d7d1a 100644 --- a/scripts/enabled_test_modules.py +++ b/scripts/enabled_test_modules.py @@ -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)"'), diff --git a/scripts/typecheck_tests.py b/scripts/typecheck_tests.py index afcddef..936444b 100644 --- a/scripts/typecheck_tests.py +++ b/scripts/typecheck_tests.py @@ -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)