3 ms·
It's possible to work around without forcing wrong type on parameter def f(l: List[int]=cast(Any, None)) -> int: if l is None: l = [
by karlicoss 5y ago
It's possible to work around without forcing wrong type on parameter
def f(l: List[int]=cast(Any, None)) -> int:
if l is None:
l = []
...
f()
Using casts is useful for all sorts of things like this when sentinel values/objects are involved. People often feel it's somehow 'wrong', but it's fine to trick the type checker as long as it's localized to neighbouring lines of code :)
- nonameiguess 5y agoYou learn something every day! I didn't even know about the cast function.