3 ms·
> raise KeyError(key) This would be flagged as unreachable I believe. mypy/pyright also supports exhaustive checking with unions def get_activation(key: Li
by throwaway343244 4y ago
> raise KeyError(key)
This would be flagged as unreachable I believe.
mypy/pyright also supports exhaustive checking with unions
def get_activation(key: Literal['sigmoid', 'tanh']) -> nn.Module:
match key:
case 'sigmoid': return nn.Sigmoid()
case 'tanh': return nn.tanh()
There are limits to mypy/pyright's exhaustive checker.. it will fail if the union is in CNF, you will need to convert it to DNF.
[1]: https://en.wikipedia.org/wiki/Disjunctive_normal_form https://en.wikipedia.org/wiki/Disjunctive_normal_form