Re:Returns: Brings functional programming to Python land
by emblaegh on Tuesday February 20, 2024 @09:11AM
(#39441496)
None of these has the functionality that the library offers, i.e. providing an interface to compose functions that consume and produce these types.
Re:Returns: Brings functional programming to Python land
by BerislavLopac on Tuesday February 20, 2024 @09:09AM
(#39441468)
I believe the recent idiomatic recommendation for the first two is to use the union type expression:
1. T | None
2. SuccessT | FailureT
Re:Returns: Brings functional programming to Python land
by epgui on Tuesday February 20, 2024 @09:11AM
(#39441506)
This is potentially quite helpful, but would you happen to have a source for that?
Re:Returns: Brings functional programming to Python land
by TrickardRixx on Tuesday February 20, 2024 @10:29AM
(#39442454)
The Union Type PEP[0] suggests that the "bitwise or" syntax is equivalent, but cleaner than typing.Union
[0]: https://docs.python.org/3/library/stdtypes.html#types-union
Re:Returns: Brings functional programming to Python land
by epgui on Monday February 26, 2024 @08:43AM
(#39511140)
Thanks! I missed that.
Re:Returns: Brings functional programming to Python land
by BerislavLopac on Tuesday February 20, 2024 @01:28PM
(#39444858)
They're both perfectly valid; but the expression style [0] is shorter and more obvious, especially compared to Optional. Even the documentation for Optional states [1]:
Note that this is not the same concept as an optional argument, which is one that has a default.
[0] https://docs.python.org/3.11/library/stdtypes.html#types-uni...[1] https://docs.python.org/3.11/library/typing.html#typing.Opti...
I also appreciate the typechecker enhancements being put forward by their custom plugins.