Skip to content

mypy crash when .mypy_cache is present #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danifus opened this issue Jul 12, 2020 · 4 comments · Fixed by #429 or #531
Closed

mypy crash when .mypy_cache is present #423

danifus opened this issue Jul 12, 2020 · 4 comments · Fixed by #429 or #531
Assignees
Labels
bug Something isn't working

Comments

@danifus
Copy link
Contributor

danifus commented Jul 12, 2020

What's wrong

Under certain circumstances, a project with a typing error will produce correct mypy errors and hints when .mypy_cache is not present but a stack trace if it is.

Here is a simplified reproduction repo demonstrating this behaviour: https://github.com/danifus/djstubs-reproduce2

  • pip install django and django-stubs
  • cd to directory containing mypy.ini
  • run mypy . --tb
  • run mypy . --tb

The first mypy . --tb produces:

second_app/models.py:10: error: Incompatible types in assignment (expression has type "str", variable has type "int")
Found 1 error in 1 file (checked 28 source files)

The second run produces:

./test_app/models.py:6: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.770
Traceback (most recent call last):
  File "mypy/semanal.py", line 4679, in accept
  File "mypy/nodes.py", line 939, in accept
  File "mypy/semanal.py", line 1001, in visit_class_def
  File "mypy/semanal.py", line 1078, in analyze_class
  File "mypy/semanal.py", line 1087, in analyze_class_body_common
  File "mypy/semanal.py", line 1147, in apply_class_plugin_hooks
  File "<venv>/mypytest/lib/python3.7/site-packages/mypy_django_plugin/main.py", line 37, in transform_model_class
    process_model_class(ctx, django_context)
  File "<venv>/mypytest/lib/python3.7/site-packages/mypy_django_plugin/transformers/models.py", line 357, in process_model_class
    initializer_cls(ctx, django_context).run()
  File "<venv>/mypytest/lib/python3.7/site-packages/mypy_django_plugin/transformers/models.py", line 71, in run
    self.run_with_model_cls(model_cls)
  File "<venv>/mypytest/lib/python3.7/site-packages/mypy_django_plugin/transformers/models.py", line 231, in run_with_model_cls
    base_manager_info=manager_info)
  File "<venv>/mypytest/lib/python3.7/site-packages/mypy_django_plugin/transformers/models.py", line 186, in create_new_model_parametrized_manager
    method_node=sym.node)
  File "<venv>/mypytest/lib/python3.7/site-packages/mypy_django_plugin/lib/helpers.py", line 329, in copy_method_to_another_class
    arguments, return_type = build_unannotated_method_args(method_node)
  File "<venv>/mypytest/lib/python3.7/site-packages/mypy_django_plugin/lib/helpers.py", line 314, in build_unannotated_method_args
    for argument in method_node.arguments[1:]:
AttributeError: attribute 'arguments' of 'FuncItem' undefined
./test_app/models.py:6: : note: use --pdb to drop into pdb

This behaviour occurs if the error is in either test_app/models.py or second_app/models.py (it currently is only in second_app/models.py).

How is that should be

Every run should produce the same (initial) output

System information

  • OS: mac
  • python version: 3.7
  • django version: 3.0.8
  • mypy version: 0.770
  • django-stubs version: 1.5
@danifus danifus added the bug Something isn't working label Jul 12, 2020
@kszmigiel
Copy link
Member

@danifus I've encountered the same problem, reinstalling both django-stubs and mypy worked for me, but I'll check your repo tomorrow and try to reproduce this bug.

@kszmigiel
Copy link
Member

@danifus fixed, sorry for the delay, I'm a bit busy with GSoC stuff at the moment

@danifus
Copy link
Contributor Author

danifus commented Jul 21, 2020

Thanks! That was actually super quick! It's great to be able to use incremental mode again :D

@javulticat
Copy link
Contributor

Any news on a new release containing this fix? Even if 1.6.0 isn't close to being ready, a minor hotfix (1.5.1?) containing this change would be incredibly appreciated - it's a significant impediment to development on large typed Django code bases to have to run mypy with no caching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
3 participants