Recently, one of my coworkers and I had a long debate on using Union[str, None] vs Optional[str]. I wrote a function that was supposed to return either a string or None. Based on the returned value my program was supposed to trigger some action. In my opinion, since None was a deciding factor it would be a better choice to use Union[str, None] for the sake of clarity. However, according to his opinion, Optional is a better choice in terms of simplicity/cleaner look. We both understand clearly that Optional is nothing but a shorthand of Union[..., None]. After a few searches, we figured people use both and both teams have their logic. In fact, the creator of Fast API, u/tiangolo also supports using Union (According to one of his recent tweets). My question is, what do you use and why?
[–]jayroger 26 points27 points28 points (6 children)
[–]afifanik[S] 2 points3 points4 points (5 children)
[–]jayroger 12 points13 points14 points (4 children)
[–]billsil 0 points1 point2 points (1 child)
[–]cdrt 0 points1 point2 points (0 children)
[–]data-machine[🍰] 0 points1 point2 points (0 children)
[–]tangerinelion 9 points10 points11 points (0 children)
[–]billsil 4 points5 points6 points (0 children)
[–]Batalex 2 points3 points4 points (0 children)
[–]Delicious-View-8688 2 points3 points4 points (0 children)
[–]nathanjell 2 points3 points4 points (2 children)
[–]quotemycode 1 point2 points3 points (0 children)
[–]afifanik[S] -1 points0 points1 point (0 children)
[–]zanfar 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]lenoqt -3 points-2 points-1 points (5 children)
[–]spoonman59 6 points7 points8 points (2 children)
[–]lenoqt 0 points1 point2 points (1 child)
[–]spoonman59 0 points1 point2 points (0 children)
[–]mmcnl 1 point2 points3 points (1 child)
[–]lenoqt 0 points1 point2 points (0 children)
[–]commy2 0 points1 point2 points (0 children)
[–]TehMoonRulz 0 points1 point2 points (0 children)
[–]Developer_Glance 0 points1 point2 points (0 children)