Replies: 1 comment 2 replies
-
This also doesn't work: # If I check with a loop, pyright acts like the variable can still be None
def example3(var1: str | None, var2: str | None, var3: str | None) -> str:
for var in (var1, var2, var3):
if var is None:
return "Oops"
# vvv Expression of type "str | None" cannot be assigned to return type "str" vvv
return var1 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think the examples speak the best for them selves. I have a number of variables and do not want to write a long chain of if conditions like this:
so I'm using the built-in any function. However pyright doesn't recognize that I checked and underlines whenever I try to use the variables where they must not be None.
Beta Was this translation helpful? Give feedback.
All reactions