-
When upgrading to pyright 1.1.181, one of my functions started to fail that pyright's 'basic' checks, and I don't understand why. A simplified example is: import inspect
from typing import Union, TypeVar
_T = TypeVar("_T")
def f(x: _T) -> Union[_T, int]:
if callable(x) and inspect.isfunction(x):
return 1
return x # <-- this line gets flagged pyright-basic flags this with
It isn't clear to me if this is a false-positive, or if I simply don't understand what this type-issue is. All of the following are OK according to pyright-basic. def f(x: _T) -> Union[_T, int]:
if callable(x): # <- no is_function
return 1
return x def f(x: _T) -> Union[_T, int]:
if inspect.isfunction(x): # <- no `callable`
return 1
return x def f(x: _T) -> Union[_T, int]:
if callable(x) and inspect.isfunction(x):
return 1
return cast(_T, x) # <- add casting This is not particularly pressing, but I would like to have a better understanding of what is going on here. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This looks to be a regression related to the fix I added for #2472. Sorry about that. I'll work on a fix for this one and augment our unit tests to cover this case. |
Beta Was this translation helpful? Give feedback.
-
No problem! Please feel free to delete this post from the discussion board, since it isn't really relevant for future readers / it should have been an Issue. |
Beta Was this translation helpful? Give feedback.
This looks to be a regression related to the fix I added for #2472. Sorry about that. I'll work on a fix for this one and augment our unit tests to cover this case.