-
Notifications
You must be signed in to change notification settings - Fork 23
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
namedtuple
Pylance error Variable not allowed in type expression
#731
Comments
Hi , thanks for reporting. I am already have a todo on another issue with NamedTuples. Im not sure yet where the problem lies:
The snippet checks out on the pyright playground Does it run OK in Micropython ? |
It runs just fine on the device, its only showing linting errors when the stubs are installed. I'm using these stubs: |
I think I found the cause of the problem In the generation of the stubs I cast the return to # .../collections.pyi
from stdlib.collections import namedtuple as stdlib_namedtuple # <--- Add this
# from typing_extensions import NamedTuple as stdlib_NamedTuple # not this
def namedtuple(name, fields) -> stdlib_namedtuple: # <-- change this
... I need some time to integrate this and generate new stubs , but for now you could manually update the stub. as I side note : I think you should add a guard clause even with the above fix,
|
ref: Josverl/micropython-stubs#731 Signed-off-by: Jos Verlinde <[email protected]>
This worked for me. Thanks!
I'm not getting that linting error, but good point. Thanks |
I could not get consistent results - I may need to update micropython-stdlib to get consistent results across the board |
Python 3.11 |
After some more testing, it seems to work fine unmodified with Clicking on the |
Ok, after experimenting more I think your solution didn't work, instead I think what was happening was it was defaulting back to my installed python types |
ref: Josverl/micropython-stubs#731 Signed-off-by: Jos Verlinde <[email protected]>
ref: Josverl/micropython-stubs#731 Signed-off-by: Jos Verlinde <[email protected]>
ref: Josverl/micropython-stubs#731 Signed-off-by: Jos Verlinde <[email protected]>
@North101 , I came to a similar conclusion. I think that means that namedtuples typechecking works only for that exact module: stdlib_stubs.collections.nametuple I'm currently working to test if i can automate updates to the typeshed stdlib stubs, and if that solves more than it may break. |
@North101 Santa delivered a present-stub for you :-) (same with ucollections) Feel free to re-open if you find any issues |
Thanks! It works |
I have the following code and i'm not sure how best to resolve the error:
Is this a problem with the stubs or a limitation of trying to use Pylance with micropython?
The text was updated successfully, but these errors were encountered: