0

So I'm having a problem with PyCharm and can't find a solution for it. It fails to recognize unresolved references:

example

The image also shows that it fails to auto-complete request.session. It only happens with .session, it works with every other attribute.

Also, this image shows that it does detect unresolved references for other stuff:

this image

I'm running it on a virtualenv, the interpreter is configured correctly and I have Django Support enabled.

Oh, and I'm using Python3 and Django 1.10.2

EDIT: Just tried it with other projects. It doesn't work with Django 1.10.x but works with Django 1.9.x

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97

1 Answers1

0

Well, in your 1st example request is a parameter to the dummy_view function - how would Pycharm know what type it is in order to check unresolved references (or offer auto-completion suggestions)?

You could add a check for request's type (also maybe a good idea to prevent bugs):

def dummy_view(request):
    assert isinstance(request, ExpectedClassType)

Or, since you tagged your question with python-3.x you could also use type hinting:

def dummy_view(request: ExpectedClassType):
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • It does know, it has Django support. It works perfectly on projects with earlier versions of Django. I'll type hint the parameter while this possible bug isn't fixed, thanks :) – Arnau Villoslada Oct 26 '16 at 12:06
  • I'm not talking about Django support - which would matter but only if the variable type would be known (and can then be looked up in Django support), I'm talking about the **actual code context**. Use the **exact** same code when comparing with the earlier versions, not like you do in this question where you compare undefined reference checking in 2 different contextes: an unknown parameter (local variable) which can be anything vs. a known class instance. – Dan Cornilescu Oct 26 '16 at 12:18