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.

3
  • Note that this is not a duplicate of stackoverflow.com/questions/21236824/… because I have no problem importing the module in the first place Commented May 27, 2020 at 9:32
  • what about if your first line is from flask import current_app and your second line is 'app = current_app' ? Commented May 27, 2020 at 11:06
  • @rajah9, that doesn't work either :( Commented May 27, 2020 at 11:18

2 Answers 2

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!

Sign up to request clarification or add additional context in comments.

1 Comment

Doesn't seem to be an issue anymore in Pycharm >=2025
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.