Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module structure not recognized by Visual Studio Code Linter #54435

Closed
bmorledge-hampton19 opened this issue Feb 18, 2022 · 6 comments · Fixed by #54104
Closed

Module structure not recognized by Visual Studio Code Linter #54435

bmorledge-hampton19 opened this issue Feb 18, 2022 · 6 comments · Fixed by #54104
Assignees
Labels
awaiting PR merge awaiting PR merge comp:apis Highlevel API related issues TF 2.8 type:bug Bug

Comments

@bmorledge-hampton19
Copy link

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 11 10.0.22000
  • TensorFlow installed from (source or binary): through pip?
  • TensorFlow version (use command below): 2.8.0
  • Python version: 3.10.2

I am very perplexed by tensorflow's module structure. I recently started using tensorflow in Visual Studio Code and immediately ran into a problem where imports from tensorflow.keras cannot be resolved by Pylance. For example, the "layers" module is not recognized from the line from tensorflow.keras import layers. Interestingly enough, the code runs fine despite this error, but the lack of support from the linter makes writing code very difficult. (For reference, I am using the "Probabilistic Bayesian Neural Networks" example script.)

My attempts to fix this issue led to a number of other discoveries which still have me confused:

  • Using from tensorflow import keras is recognized by the linter, but the linter still can't offer any helpful predictions off of the keras module. In this instance, replacing references to layers with keras.layers still work, despite no indication from the linter that they should.
  • Importing keras directly (2.8.0) instead of through tensorflow is recognized, and keras.layers is still valid, but hints from linting are still not present, and other parts of the code will break unexpectedly. For example, a call to keras.optimizers.RMSprop, is invalid even though keras.optimizers is recognized and both are recognized if keras is imported through tensor flow.
  • Importing keras through tensorflow.python behaves similarly to directly importing keras.
  • Even though keras.layers is not recognized by the linter after importing just keras, the linter does recognize from keras import layers and offers completions for layers after the fact.
  • from tensorflow import keras was recognized in tensorflow 2.7.0. This issue only started when I updated.

Admittedly, my understanding of packaging and linting in Python is somewhat limited, but I've never had issues like this with any other package I've worked with. Am I missing something obvious here? Is this a known issue? If this kind of structure is intentional, what is the rationale behind it? Are there known workarounds/resources that I could use to better understand this issue?

Thanks in advance for the help.

@bhack
Copy link
Contributor

bhack commented Feb 18, 2022

@tilakrayal
Copy link
Contributor

@bmorledge-hampton19 ,
The issue will move to closed status once the PR is merged.

@bmorledge-hampton19
Copy link
Author

Thanks for the links. They are very helpful. My apologies for rehashing an issue that is clearly already recognized.

@Arkaikus
Copy link

Hope the pr gets merged soon that linter error it's driving me nuts

@BlueskyFR
Copy link

BlueskyFR commented Mar 6, 2022

Thanks for the links. They are very helpful. My apologies for rehashing an issue that is clearly already recognized.

Don't apologize, the issue has been around since TF 2.0 release and nothing was ever done about it, it is unacceptable that every new release breaks PyLance.
I am not saying that this is either TF or PyLance's fault, but that the larger part of the community probably using VSCode, the support for it should be taken more seriously IMO.

@tilakrayal tilakrayal added the awaiting PR merge awaiting PR merge label Apr 1, 2022
@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting PR merge awaiting PR merge comp:apis Highlevel API related issues TF 2.8 type:bug Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants