3 ms·
Python's equivalent of Rust's Enums would be the __match_args__ machinery rather than enums themselves, ironically. They aren't as ergonomic or type-safe, and
by qsort 3y ago
Python's equivalent of Rust's Enums would be the __match_args__ machinery rather than enums themselves, ironically.
They aren't as ergonomic or type-safe, and rather surprisingly the match statement is not an expression in Python's grammar, but regardless of its problems the match statement is very powerful, even more so than static equivalents.
- GalaxySnail 3y agoIMO Python's equivalent of Rust's Enums would be `typing.Union` [1]. It is more ergonomic and type-safe, and mypy supports type narrowing [2] and exhaustiveness checking on it [3]. [1] https://docs.python.org/3/library/stdtypes.html#types-union https://docs.python.org/3/library/stdtypes.html#types-union [2] https://mypy.readthedocs.io/en/stable/type_narrowing.html https://mypy.readthedocs.io/en/stable/type_narrowing.html [3] https://docs.python.org/3/library/typing.html#typing.assert_never https://docs.python.org/3/library/typing.html#typing.assert_...