Two python method are defined as:
def function() -> Optional[ast.Module]:
pass
def something(t: ast.Module) -> None:
pass
In a caller:
var = function()
if var:
do_something(var)
The type-checker complains that I can't pass an Optional[t] to t. I imagine that there's some sort of casting mechanism, but it escapes me.
To be precise, this is a unit test and looks like:
self.assertIsNotNone(var)
do_something(var)
With respect to possible duplicate Optional type annotation. Using value after checking if is None?,
new_var: ast.Module = var
gets the same type error.
Is an 'if' required?