The Python here works just fine, but mypy doesn't like it...
example.py:14: error: Argument 1 to "callback" has incompatible type "Optional[str]"; expected "str"
The if url is None:
conditional should prevent the url
in the else
block from ever being None
,
but maybe it doesn't work like that? Or I'm just wrong...
The answer here is kind of ugly... The mypy type checker doesn't appear to be aware of the context for
url
across the function boundary ofcb
, so it thinksurl
still has typeOptional[str]
even though that's made impossible by the conditional. This can be "resolved" by defining the callback for thestr
case asGross, but it works and the type checker is satisfied. Thanks again to @RadicalZephyr for the assist.