Re:Statically-typed error handling in Python using Mypy
by dharmab on Sunday December 08, 2019 @07:16PM
(#21739467)
How are optional keys a nuisance? I find that using the patterns:
Or:
Works as expected. Nested optional keys can be a bit annoying, although:
seems to work.
[ Parent
| on HN ]
Re:Statically-typed error handling in Python using Mypy
by avremel on Sunday December 08, 2019 @07:22PM
(#21739494)
I was referring to defining optional keys.
If you have a dict with some keys which are optional, you need to create a separate subclass (with `total=False`) just for those optional keys.
With TypeScript, I can just use `key?: type`.
https://mypy.readthedocs.io/en/latest/more_types.html#mixing...