joedevivo / vscode-circuitpython

VSCode extension for Adafruit's CircuitPython
MIT License
116 stars 33 forks source link

[BUG] "h:\code.py" is overriding the stdlib module "code" #106

Open rpgrunwald opened 1 year ago

rpgrunwald commented 1 year ago

Describe the bug Error message "h:\code.py" is overriding the stdlib module "code"

To Reproduce Steps to reproduce the behavior: Add CIRCUTPY drive with Open Folder Open code.py

image

Desktop (please complete the following information):

Additional context Adafruit Circuit Playground Express with adafruit-circuitpython-circuitplayground_express-en_US-7.3.3.uf2

IrregularShed commented 1 year ago

This issue is unrelated to the extension. It's occurring due to the way the Pylance language server is configured; Pylance has no concept of CircuitPython or MicroPython and is attempting to treat what it has found in the same way as it would 'proper' Python. I had the same experience, and fixed it like this:

Hope that helps!

joshmarinacci commented 1 year ago

This might be a good thing to add to the extension docs. I ran into it as well.

stefan-sherwood commented 1 year ago

According to the documentation:

CircuitPython looks for a code file on the board to run. There are four options: code.txt, code.py, main.txt and main.py. CircuitPython looks for those files, in that order, and then runs the first one it finds. While code.py is the recommended name for your code file, it is important to know that the other options exist.

So an arguably better solution is to name your main program file main.py instead of code.py. Then you'll still get (useful, IMO) warnings when you override modules but you won't have the problem reported here.

VashJuan commented 10 months ago

Much better solution (IMHO) is just to rename code.py to main.py: it won't conflict with the standard libraries & will still get run on boot.