Description
It is possible to have Mypy complain if a case is missed when branching on an instance of an Enum, see mypy issue 6366.
This could be used in psbt.py
, function check_witness_and_nonwitness_utxo_in_sync
where all cases of PSBT_InKeyType
are matched. Instead of raising AssertionError
, _assert_never
could be called, which would trigger a Mypy error on compile time. If Mypy isn't run, it still fails on runtime. So there is no disadvantage except the reader needing to learn the NoReturn
type.
It could also be used in PSBT_Input.merge
, but it seems that Mypy is not smart enough to detect that "(a and b) or (not a and b), (a and not b), (not a and not b)" is always true. It would probably work to introduce an enum with 4 cases for this or maybe it would work with a (bool, bool) tuple, but I don't know if Mypy is smart enough for this, and I don't know if you think it is worth it.