Skip to content

Crash when return type of a Manager method is a forward reference #438

Closed
@danifus

Description

@danifus

Bug report

What's wrong

mypy crashes when the return type of a manager method is a forward reference (similar to #373)

I've created a reproduction repo: https://github.com/danifus/djstubs-reproduce

Steps:

cd to the directory containing mypy.ini
run mypy . --tb
./test_app/models.py:10: 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.782
Traceback (most recent call last):
  File "mypy/semanal.py", line 4691, in accept
  File "mypy/nodes.py", line 939, in accept
  File "mypy/semanal.py", line 1011, in visit_class_def
  File "mypy/semanal.py", line 1088, in analyze_class
  File "mypy/semanal.py", line 1097, in analyze_class_body_common
  File "mypy/semanal.py", line 1157, in apply_class_plugin_hooks
  File "<venvdir>/djmypytest/lib/python3.8/site-packages/mypy_django_plugin/main.py", line 37, in transform_model_class
    process_model_class(ctx, django_context)
  File "<venvdir>/djmypytest/lib/python3.8/site-packages/mypy_django_plugin/transformers/models.py", line 357, in process_model_class
    initializer_cls(ctx, django_context).run()
  File "<venvdir>/djmypytest/lib/python3.8/site-packages/mypy_django_plugin/transformers/models.py", line 71, in run
    self.run_with_model_cls(model_cls)
  File "<venvdir>/djmypytest/lib/python3.8/site-packages/mypy_django_plugin/transformers/models.py", line 230, in run_with_model_cls
    custom_manager_type = self.create_new_model_parametrized_manager(custom_model_manager_name,
  File "<venvdir>/djmypytest/lib/python3.8/site-packages/mypy_django_plugin/transformers/models.py", line 183, in create_new_model_parametrized_manager
    helpers.copy_method_to_another_class(new_cls_def_context,
  File "<venvdir>/djmypytest/lib/python3.8/site-packages/mypy_django_plugin/lib/helpers.py", line 351, in copy_method_to_another_class
    assert bound_return_type is not None
AssertionError:
./test_app/models.py:10: : note: use --pdb to drop into pdb

How is that should be

No crash :p

System information

  • OS:
  • python version: 3.8.4
  • django version: 3.0.8
  • mypy version: 0.782
  • django-stubs version: ca10ee9 (current master head)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcrash"Internal error" crashes from mypymypy-pluginIssues specific to mypy_django_plugin

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions