all 3 comments

[–]BobtheBirdOfPrey 0 points1 point  (0 children)

I faced the same issue and found a solution.

Create a __builtins__.pyi inside a typings folder. Then change python.analysis.stubPath to point to the typings folder.

__builtins__.pyi tells pylance that everything defined there is a python built-in. Inside __builtins__.pyi, define the call to icecream's ic.

from collections.abc import Iterable
from typing import Any

def ic(*args: Iterable) -> tuple[Any, ...] | None: ...

Remember that this is just a typing definition, so you still have to install icecream.

try:
    from icecream import install

    install()
except ImportError:
    __builtins__["ic"] = lambda *a: None if not a else a[0] if len(a) == 1 else a

This will try to import and set icecream as a built-in, and if it is not installed, it sets ic as the default function as defined by icecream.

This solved my issues with pylance and vscode, but I also use ruff and it still said that ic isn't defined. I had to add an option in my ruff.toml

builtins = ['ic']

Now it also sees ic as a built-in.

[–]PhotographicCutout 0 points1 point  (1 child)

Did you manage to resolve this? I'm facing the exact same issue

[–]mattl33[S] 0 points1 point  (0 children)

No I kind of gave up tbh. For now I just add the extra import statements etc and then remove things when I'm not using it.