Skip to content

False positive on "unresolved import" for tensorflow.keras #7390

@kbrose

Description

@kbrose

Environment data

  • VS Code version: 1.38.0
  • Extension version (available under the Extensions sidebar): 1.38.0
  • OS and version: macOS Mojave, 10.14.6
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.8
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pyenv
  • Relevant/affected Python packages and their versions: tensorflow 1.14, 2.0
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): language server (setting is false)

Expected behaviour

Create python file

from tensorflow.keras.layers import Input

inp = Input(shape=(1,))
print('Done!')

Expect no errors, expect a useful information tooltip when hovering over Input.

Running this python file prints "Done!", i.e. this is not actually an unresolved import.

Actual behaviour

unresolved import error is shown. No useful information tooltip.

image

Other note

If I change the import to

from tensorflow.python.keras.layers import Input  # inserted ".python"

things work as expected. This is a non-standard, undocumented import path (so I'd rather not do it).

Steps to reproduce:

  1. Create a python file containing above code.
  2. Observe error.

Related issues

This seems related to #6241, but as best as I can tell there's no sys.path shenanigans going on inside tensorflow (and thus not a duplicate). The two following files look reaosnable to me, but I'll admit I don't know much about how the tensorflow pypi package is created. There could be weird stuff inserted at build time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions