3 ms·
(2020). Things have arguably become even nicer (although slightly more divergent between the two) since then: Python's `Optional[T]` can now be written as `T |
by woodruffw 3y ago
(2020).
Things have arguably become even nicer (although slightly more divergent between the two) since then: Python's `Optional[T]` can now be written as `T | None`, and the core container types can now be annotated directly (e.g. `List[T]` becomes `list[T]`).
Combined via pyO3[1], Python and Rust are a real joy to write together.
[1]: https://github.com/PyO3/pyo3 https://github.com/PyO3/pyo3
- tayo42 3y agoDidn't notice the date, I was confused about the comment about pattern matching
- diarrhea 3y agoI don’t think the new way to write None is an improvement in this case. I use the pipe as a replacement for Union (of which Optional is a special case, but oddly, there is prefer to use Optional; it reads nicely).
- kzrdude 3y agoI'm not that deep into type annotations in Python, but I'm not a fan of type-only structures, or mixing concrete with type aliases. That is, `list[T]` is a concrete list, but `Optional[T]` is either a plain T or a plain None. There is no class called Optional.
- rirze 3y agoI prefer the new way, to me it's explicit about the type of Object that can be passed in.