Better HN
topnewbestaskshowjobs
Log inSign up

throwaway343244

5 karma · joined Aug 23, 2022 (4y ago) · 4 submissions

Submissions

comment 4y ago · link · parent

> 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

comment 4y ago · link · parent

> If you enforce them then you can't do duck typing,

This is a little misleading as mypy and pyright both support structural typing.