Consider the following valid Python code:
import numpy
class Wrapper:
def __init__(self, func):
self.func = func
def __get__(self, instance, owner):
return lambda **kwargs: self.func(instance, wrapped=True, **kwargs)
class Foo:
@Wrapper
def __init__(self, **kwargs):
print(f'{kwargs}')
Foo(bar=numpy.nan)
Pyright (tested with 1.1.41) will incorrectly report the numpy import as unused.
While I'm not very familiar with Pyright's internals, a quick debug session indicates the following:
validateConstructorArguments invokes validateCallArguments for Foo(bar=np.nan). The inferred type of __init__ is an object (Wrapper) and it attempts to look up Wrapper.__call__. This failed call to getTypeFromObjectMember doesn't set argumentErrors to true (not sure if that's intentional), but consequently, the numpy reference in the argument doesn't get added to accessedSymbolMap.
Consider the following valid Python code:
Pyright (tested with
1.1.41) will incorrectly report thenumpyimport as unused.While I'm not very familiar with Pyright's internals, a quick debug session indicates the following:
validateConstructorArgumentsinvokesvalidateCallArgumentsforFoo(bar=np.nan). The inferred type of__init__is an object (Wrapper) and it attempts to look upWrapper.__call__. This failed call togetTypeFromObjectMemberdoesn't setargumentErrorstotrue(not sure if that's intentional), but consequently, thenumpyreference in the argument doesn't get added toaccessedSymbolMap.