Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is potentially quite helpful, but would you happen to have a source for that?


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


Thanks! I missed that.


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...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: