pythonstubs icon indicating copy to clipboard operation
pythonstubs copied to clipboard

import @overload to fix linting error

Open ed-p-may opened this issue 1 year ago • 0 comments

Hi,

I am using Grasshopper-stubs in VSCode and I am running into a problem with some overloaded classes? It appears that the fix is to include an explicit overload import in the stub .pyi file?

Scenario:

from Grasshopper.Kernel.Data import GH_Path
test_path = GH_Path(1)

give me the linting error:

Argument of type "Literal[1]" cannot be assigned to parameter "Other" of type "GH_Path" in function "init" "Literal[1]" is incompatible with "GH_Path"

Screenshot 2024-01-26 at 4 12 44 PM

It works fine at runtime of course, since an int is an acceptable argument type for GH_Path.

Proposed Fix

It appears that VSCode is not able to automatically resolve the @overload in the stub file for some reason, which is leading to this error? Screenshot 2024-01-26 at 4 13 56 PM

However, if overload is imported from typing: from typing import Tuple, Set, Iterable, List, overload Then in that case, the linting seems to resolve properly:

Screenshot 2024-01-26 at 4 15 31 PM

ed-p-may avatar Jan 26 '24 21:01 ed-p-may