-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Existing tensorflow stubs modules and classes can not infered by pyright/pylance? #11052
Comments
I'd prefer moving the discussion to a new issue. That being said, I wonder if pyright is picking up Originally posted by @Avasam in #7144 (comment) |
This simple script confirms this: import tensorflow as tf
reveal_type(tf)
reveal_type(tf.keras) mypy prints:
While pylance (which uses pyright under the hood, as far as I know) reports:
(Please ignore the German error messages. For some reason the pylance developers though it was a good idea to translate error messages, without an apparent way to configure the language used.) Maybe @erictraut can shed some light on this issue. |
Hmm, I'm not able to repro the problem if I install the I am able to repro the behavior reported by the OP. Pyright is evaluating the expression |
The intent of
When I remove explicit re-export locally then pylance gives me an error there of,
My own local stubs don't have getattr as for typeshed I leave incomplete stubs with getattr to avoid giving false positives, but my personal/work usage I tend to be stricter and take false positives instead of false negatives for tensorflow. Although adding 1 getattr to |
Digging into this further, I think there is a bug in pyright here. It appears to be in some code added by the pylance team to support some language server features, and it affects stub packages where the "py.typed" file indicates they are "partial" stubs. I'll work with the pylance team to figure out what's going on here. |
Thanks @erictraut. Apart from the issue in pyright, I also thought of something else:
This is the first time I've consciously tried to deal with partial stubs. I'm not quite sure whether I understand |
getattr is necessary as This comment touches that idea. That would likely need discussion here. I'm unsure it's good choice for tensorflow though just because tensorflow abuses import system heavily. For a more normal large library I could see partial stub modules being useful. Currently tensorflow stubs have many partial files (happy to review contributions) so |
@alkatar21 without |
@heejaechang, I provided detailed repro steps in this issue. If you weren't able to repro the problem following those steps, please respond in that issue, and we can work together to figure out why you're seeing something different. |
As this seems like a Pylance issue (microsoft/pylance-release#5139), I'm closing this here. Thanks to everyone for analyzing this! |
I just tried the stubs with the
![grafik](https://private-user-images.githubusercontent.com/61387986/284629336-7f08da4a-748d-4311-a6cc-d59794b1bedc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1NTE4ODQsIm5iZiI6MTcyNTU1MTU4NCwicGF0aCI6Ii82MTM4Nzk4Ni8yODQ2MjkzMzYtN2YwOGRhNGEtNzQ4ZC00MzExLWE2Y2MtZDU5Nzk0YjFiZWRjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA1VDE1NTMwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc2N2MwMTZlNjUzMTBjYmY1Yzc5ZjQzN2E4MGM3MjVkMmI1YjU4ZGNkMzVjMjZmMDkyYWZmOTA3OWZhYWQ5YzEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.13-Qm6uH2QJ6hdKQ7Og1bO1rzEr6jnLtyBu3GXluRxQ)
types-tensorflow
package with VSCode and pyright(I use pylance) and don't quite understand why in the following example bothlayers
andDense
areIncomplete
?As this is implemented:
typeshed/stubs/tensorflow/tensorflow/keras/layers.pyi
Line 116 in 5fd2e9b
Originally posted by @alkatar21 in #7144 (comment)
The text was updated successfully, but these errors were encountered: