Python - unresolved reference on some nested imports

Answered

I'm observing Idea complaining about unresolved references when referencing modules inside an imported module.

An example might make this clearer:

from tensorflow import keras
keras.Sequential()

In the above, Idea will complain that `Sequential` is an unresolved reference.

When I ctrl+click on the `import keras`, it leads me to a directory with an `__init__.py` containing:

from tensorflow.python.keras import Input
from tensorflow.python.keras import Model
from tensorflow.python.keras import Sequential
from tensorflow.python.keras import __version__
from tensorflow.python.keras.api._v1.keras import activations
from tensorflow.python.keras.api._v1.keras import applications
from tensorflow.python.keras.api._v1.keras import backend
from tensorflow.python.keras.api._v1.keras import callbacks
from tensorflow.python.keras.api._v1.keras import constraints
from tensorflow.python.keras.api._v1.keras import datasets
from tensorflow.python.keras.api._v1.keras import estimator
from tensorflow.python.keras.api._v1.keras import experimental
from tensorflow.python.keras.api._v1.keras import initializers
from tensorflow.python.keras.api._v1.keras import layers
from tensorflow.python.keras.api._v1.keras import losses
from tensorflow.python.keras.api._v1.keras import metrics
from tensorflow.python.keras.api._v1.keras import mixed_precision
from tensorflow.python.keras.api._v1.keras import models
from tensorflow.python.keras.api._v1.keras import optimizers
from tensorflow.python.keras.api._v1.keras import preprocessing
from tensorflow.python.keras.api._v1.keras import regularizers
from tensorflow.python.keras.api._v1.keras import utils
from tensorflow.python.keras.api._v1.keras import wrappers

Idea seems to recognize (offers autocompletion on) all the `...api._v1.keras` imports. But not the first 4 (Input, Model, Sequential, or __version__).

If I create a brand new project in PyCharm, the issue is not present, and `Sequential` is properly recognized. However if I open that same project in Idea, the issue is present. So I'm not sure if I have something misconfigured in Idea, or if the Idea python plugin is bugged.

 

This is observed with Idea 2019.2 and python plugin 2019.2.192.5728.98

0
3 comments

Hi,

This looks like a bug in Python plugin. I filed an issue about it https://youtrack.jetbrains.com/issue/PY-37795, feel free to vote and leave comments.

1
Avatar
Permanently deleted user

@Patrick, Hi, do you have find a solution in IntelliJ now?

0

@... That should have been fixed in the latest IntelliJ IDEA. 

Please update your installation to 2020.3

0

Please sign in to leave a comment.