typeddjango / django-stubs

PEP-484 stubs for Django
MIT License
1.56k stars 433 forks source link

django-stubs package is reason for "Unresolved tag" errors in PyCharm #555

Open egregors opened 3 years ago

egregors commented 3 years ago

Bug report

What's wrong

Looks like presence django-stubs package breaks PyCharm tag resolving mechanism for Django templates. 2021-01-11_10-58-29

Literally, all Django template tags (built-in or custom) become unresolved and the only way to fix it – remove django-stubs package .

This is a huge thread from JetBrains tech support site about this problem. https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003433179-Pycharm-suddenly-not-detecting-ANY-Django-tags-in-template

How is that should be

I believe, stubs package shouldn't break the base mechanisms for one of the most popular Python IDE.

System information

sobolevn commented 3 years ago

@egregors Hi! Thanks for letting us know about the problem. Sadly, I don't know what should we fix to solve this issue.

I am not a PyCharm user, so I cannot tell if it is the same for me.

mariyabytes commented 3 years ago

I spent some time messing around with django-stubs files, and found out something interesting. Temporary fix : If you rename the __init__.pyi file in the site-packages/django-stubs folder to __init__.py, all Django template tags (built-in or custom) start working again, and it has no observable affect on the working of the django-stubs package.

Even having an empty __init__.pyi file in the django-stubs folder with nothing else breaks Pycharm's analyzer. This is probably something that is an internal issue with pycharm, and not a problem with this package.

Now I went through mypy's documentation for stub packages to check whether changing from __init__.pyi to __init__.py actually makes a difference, and it seems that it's just a convention. Even PEP 561's spec doesn't restrain you to use the .pyi extension for __init__ files of stub-only packages. So technically, you could rename it manually, at least till PyCharm releases a patch.

1oglop1 commented 3 years ago

There is a PyCharm an existing issue: https://youtrack.jetbrains.com/issue/PY-37744

intgr commented 3 months ago

Is this template tags issue still affecting anyone?

The issue mentioned by 1oglop1 PY-37744 has been marked fixed (will be part of the next release), but that issue was about Model/QuerySet type inference, so I doubt it had any effect on Django template tags.

intgr commented 3 months ago

If this issue still occurs for anyone, then please report a new PyCharm ticket at https://youtrack.jetbrains.com/issues/PY