intellij-micropython icon indicating copy to clipboard operation
intellij-micropython copied to clipboard

Pycharm false alarm: Unresolved attribute reference 'toggle' for class 'Pin'

Open Omid888 opened this issue 1 year ago • 6 comments

Pycharm throws a warning for this working code:

from machine import Pin
from time import sleep

some_led = Pin(25, Pin.OUT)

while True:
    some_led.toggle()
    sleep(1)

Although the code works correctly on the microcontroller, pycharm could not understand the toggle() function and shows this warning: Unresolved attribute reference 'toggle' for class 'Pin'

Since other IDEs (vscode & thonny) does not have this problem, I reached out to report it.

P.S: As you have probably guessed, pycharm's auto-completion does not work for this function, but it works for other functions.

Omid888 avatar Aug 02 '24 15:08 Omid888

the code works correctly on the microcontroller

Would you kindly specify the board?

lancelote avatar Aug 03 '24 11:08 lancelote

@lancelote

raspberrypi pico micropython version: 1.23.0

Omid888 avatar Aug 03 '24 11:08 Omid888

import onewire has this problem too.

Omid888 avatar Aug 03 '24 13:08 Omid888

There is a similar issue with const, which has to be imported as from micropython import const to make PyCharm errors go away, works perfectly fine on the micro controller regardless of the import.

ESP32 S2

lukaskremla avatar Aug 13 '24 19:08 lukaskremla

@Josverl Do you have any suggestions?

Omid888 avatar Aug 16 '24 11:08 Omid888

I'm assuming that you use the micropython-stubs for this, and followed the pycharm config for it

Please note that the stubs provided by the pycharm feature are different, and older, although there is some shared work here, there will be differences.

const is indeed a builtin that does not need an import on micropython, and for pylance/py right this can be configured through a __builtin__.pyi stub.

I have not yet found a way to configure the same in pycharm.

Josverl avatar Aug 18 '24 08:08 Josverl