6

I'm using VScode to write MicroPython code. The linting and code completion is quite decent, but as there are quite a few differences between CPython and MicroPython, I think it could be better.

Is there a way for pylint to :

In other words I'd like to prevent errors and warnings such as these:

warnings

I've looked at a promising approach by Thonny to extract module information and save that in module/APIstubs, and extend that to more complete prototypes. However that would still require pylint to include and prioritize these over CPython.

Is that something that can be configured in pylint and/or Python, and if so, how would I go about that?

Update : I have a decent partial solution on https://github.com/Josverl/micropython-stubber and there also may be interest to solve this more generally in vscode

Jos Verlinde
  • 1,468
  • 12
  • 25
  • 1
    What if you added the stubs directory to PYTHONPATH of pylint process? – Aivar Jan 12 '19 at 05:26
  • I gave that a try by adding `init-hook='import sys; sys.path.insert(1,"C:\\Develop\\thonny\\thonny\\plugins\\micropython\\api_stubs\\")'` to `.pylintrc`, and that does work to a degree. 1. the '[pylint]' errors change, apparently the stubs picked up , but are not correct yet ( missing returns type , parameters etc) 2. the `[Python]` warnings however, are unaffected – Jos Verlinde Jan 12 '19 at 13:21
  • Alternately, set the python.linting.pylintPath to an appropriate version of Pylint for the Python interpreter being used. – Jos Verlinde Jan 14 '19 at 09:37
  • 1
    @JosVerlinde there probably isn't one for MicroPython yet. However this question would probably reach the best audience on the [MicroPython forum](https://forum.micropython.org/index.php). – nekomatic Jan 14 '19 at 11:39

1 Answers1

1

In order to achieve this a few things are needed:

  • Stub files for the native / enabled modules in the firmware using PEP 484 Type Hints
  • Specific configuration of the VSCode Python extensions
  • Specific configuration of Pylint
  • Suppression of warnings that collide with the MicroPython principals or code optimization.

A detailed explanation can be found in: https://github.com/Josverl/micropython-stubber#boost-micropython-productivity-in-vscode

If you do not want to generate and gather the subs yourself, common MicroPython stubs stored in the sister-repo: https://github.com/Josverl/micropython-stubs

Jos Verlinde
  • 1,468
  • 12
  • 25