paulober / Pico-W-Stub

MicroPython stubs for the Raspberry Pi Pico W
Apache License 2.0
10 stars 3 forks source link

Incorrect linting of dictionaries with string keys #13

Closed asltpo closed 11 months ago

asltpo commented 11 months ago

Describe the bug Steps:

  1. Start VSCode
  2. Create a new project and configure it as a MicroPico project using MicroPico > Configure Project
  3. Create a new Python file and create a dictionary object with a string key (example code below).

Expected behaviour: No warnings or errors.

Actual behaviour: Pylance reports the following error:

Dictionary key must be hashable
  Type "Literal['key1']" is not hashable Pylance(reportGeneralTypeIssues)

Notes:

The expected behaviour is restored if:

Code or Screenshots

Python code:

my_dict = {"key1": 1}

Version info VSCode v1.82.2 Pylance v2023.9.20 MicroPico v3.2.5

MG-LSJ commented 11 months ago

Having the same issues.

doing this fixes it: Adding

    def __hash__(self) -> int: ...

to the end of class int (and class str) in stdlib -> builtins.pyi removed the warnings from pylance.

https://github.com/Josverl/micropython-stubs/issues/723#issuecomment-1703723773

bernd-o-mat commented 11 months ago

Same Pylance behaviour to me. False positive. "Dictionary key must be hashable..."

Snipeye commented 11 months ago

New to uPy, but I'm glad I found this - updating the stdlib buildints.pyi fixed it for now but I'll have to do that for any class I want to use as a dictionary key to avoid squiggles.

Just adding my $0.02 to request a please fix!

paulober commented 11 months ago

Expect a fix in the next few hours...

paulober commented 11 months ago

@Snipeye @asltpo does https://github.com/paulober/MicroPico/releases/tag/v3.4.0 fix your issues? (it's only MicroPython v1.20.0 but v1.21.0 will follow in the next few days)

Snipeye commented 11 months ago

After updating I no longer see the squiggles, and my builtins.pyi was updated. (That is to say: I don't think it was just a holdover from my kludges last night). Thanks, @paulober !

asltpo commented 11 months ago

Ditto, if I follow the steps from my original post but using:

VSCode v1.83.1 Pylance v2023.10.30 MicroPico v3.4.0

I get the correct behaviour.

Many thanks!