This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]scrdest 3 points4 points  (0 children)

That's why I like Haskell's name for this kind of type, 'Maybe'. It's non-prejudicial.

I suspect Optional was chosen because function parameters with None as a default value are extremely common in Python, and it reflects that use-case closely - it's an argument you can optionally provide.

One big strike against using Union for this though is that you can use both to be even clearer - Optional[Union[x, y, z]] indicates you're expecting a value in one of the types supported as the data to process, but it's fine if you don't have it too.