3 ms·
Both mypy and pyright/pylance do the right thing when things are guarded with explicit None checks and the wrong thing with “or”, so even though I prefer “or” o
by dragonwriter 5y ago
Both mypy and pyright/pylance do the right thing when things are guarded with explicit None checks and the wrong thing with “or”, so even though I prefer “or” otherwise when its gated upstrean so that None is the only falsey value it should get, I’ve taken recently to using explicit checks to make typecheckers happy.
- Mehdi2277 5y agoThat's not been my experience. I frequently use or way and have both mypy/pyright enabled. Testing this toy function, from typing import List, Optional def f(x: Optional[List[int]]): x = x or [] reveal_type(x) mypy and pyright both show List[int] as type of x at the end and correctly drop None.