
I agree with Eric, `assert_never` is a good feature on its own. And it is a helper I re-implement in almost every project. I believe that standardizing will benefit many use-cases and many people. And it completely solved exhaustiveness checking with something like `case _unreachable: typing.assert_never(_unreachable)` ср, 19 янв. 2022 г. в 20:25, Eric Traut <eric@traut.com>:
Pattern matching support has been implemented in pyright for about a year now. We have received one or two requests for a way to enforce exhaustion through a configuration option. So far, we've resisted adding this because there are valid use cases of `match` that don't involve exhaustion. Our viewpoint is that it's better to indicate exhaustion explicitly if that's your intent. If there's sufficient interest in a configuration option (similar to the proposed "--exhaustive-match" switch in mypy), we might be compelled to add this in pyright as well. I don't think we would enable it by default, even in strict mode.
I'm pretty negative on having a static type checker generate errors on an `assert False` statement, even if (especially if) it's only in this specific context. It's a non-obvious special case, it's too specific (e.g. does it work if you also provide an error string?), and this statement has nothing to do with type checking. I'd be reluctant to implement such as solution in pyright even if mypy chose to add this special case.
I'd strongly prefer to standardize on `assert_never`. Regardless of what statement we choose here, we need to train users how to express that they want to enforce exhaustive testing, and `assert_never` is the proper way to do that using types. Furthermore, `assert_never` already works in all type checkers and has utility outside of match statements. It would be nice to include `assert_never` in one of the typeshed stdlib stubs so users don't need to implement it in their own code.
-Eric
-- Eric Traut Contributor to Pyright & Pylance Microsoft _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: n.a.sobolev@gmail.com