2

I have a flask app that I'm developing in PyCharm on MacOS.

When I try to import the flask current app like this:

from flask import current_app as app

I get an inspection error: Unresolved reference 'current_app', but when I run the the project I get no runtime errors.

If I "import" the current app like this:

import flask
app = flask.current_app

then PyCharm is happy.

I have the same problem with local imports. How can I fix this.

nobody
  • 1,144
  • 1
  • 10
  • 20
  • Note that this is not a duplicate of https://stackoverflow.com/questions/21236824/unresolved-reference-issue-in-pycharm because I have no problem importing the module in the first place – nobody May 27 '20 at 09:32
  • what about if your first line is `from flask import current_app` and your second line is 'app = current_app' ? – rajah9 May 27 '20 at 11:06
  • @rajah9, that doesn't work either :( – nobody May 27 '20 at 11:18

2 Answers2

3

I opened a ticket with JetBrains support, and after a long investigation they found the issue.

Somehow my __init__.py files got associated with text files, and that broke the resolver. I fixed it by going to Settings | Editor | File Types | Text | Registered patterns and deleting __init__.py from the registered patterns.

Thank you JetBrains for the great support!

nobody
  • 1,144
  • 1
  • 10
  • 20
1

I tried the solution that the user nobody suggested. However, the file __init__.py was not within the Registered Patterns in the Text file type.

I searched lot of similar questions and also tried their suggestions but nothing worked. So I came up with the idea to add __init__.py into the --> Settings | Editor | File Types | Python | Registered patterns

Ss

And the unresolved reference error is now solved.

person_v1.32
  • 2,641
  • 1
  • 14
  • 27