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...
I'm not so keen on the
assert
in production code here.I prefer to have an if starement
if url is None:
then raise some blank error
raise ValueError
as you said, its impossible for this error to actually get raised, but it should satisfy mypy, and I think it looks a bit nicer than the assertion :)