On Mon, 24 Oct 2022 at 14:15, Dan Stromberg <drsali...@gmail.com> wrote: > I've found that mypy understands simple assert statements. > > So if you: > if f is not None: > assert f is not None > os.write(f, ...) > > You might be in good shape.
Why can't it simply understand the if statement? I'm not a fan of coddling a type system like this. The entire point of type checking is to help you find bugs more efficiently, so if you have to repeat yourself every time you do these kinds of checks just so that mypy is satisfied, that's counter-productive (case in point: what happens if you say "if fn is not None: assert f is not None"? Now you've introduced a bug just to deal with the type system). ChrisA -- https://mail.python.org/mailman/listinfo/python-list