Skip to content

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

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 Aug 5, 2020 · 4 comments
Closed

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

danifus opened this issue Aug 5, 2020 · 4 comments
Assignees
Labels
bug Something isn't working crash "Internal error" crashes from mypy mypy-plugin Issues specific to mypy_django_plugin

Comments

@danifus
Copy link
Contributor

danifus commented Aug 5, 2020

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)
@danifus danifus added the bug Something isn't working label Aug 5, 2020
@kszmigiel
Copy link
Member

@sobolevn should I do the fix on the master branch or in the refactor?

@sobolevn
Copy link
Member

sobolevn commented Aug 5, 2020

Whatever you think is best @kszmigiel

kszmigiel pushed a commit to kszmigiel/django-stubs that referenced this issue Aug 5, 2020
@kszmigiel
Copy link
Member

@danifus @sobolevn
I've fixed this issue on refactor branch here (added test too): 1ae7eca
I've encountered error with annotating ModelA.objects here, I've managed to fix it earlier with from_queryset, so I'll try to do the same here

kszmigiel pushed a commit to kszmigiel/django-stubs that referenced this issue Aug 15, 2020
@intgr intgr added mypy-plugin Issues specific to mypy_django_plugin crash "Internal error" crashes from mypy labels Nov 8, 2022
@flaeppe
Copy link
Member

flaeppe commented Sep 23, 2023

The reported traceback is no longer relevant and I can't reproduce. I'll close this off, feel free to reopen with a breaking case.

@flaeppe flaeppe closed this as completed Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash "Internal error" crashes from mypy mypy-plugin Issues specific to mypy_django_plugin
Development

No branches or pull requests

5 participants