#Python optional params

1 messages ยท Page 1 of 1 (latest)

tender cradle
#

Yes, optional params are supported but they're based on having a default or not, not by whether it allows None (which is what Optional[str] does).

#

Do you mind showing how you're defining that?

undone forge
#

I've since switched Optional[str] to str | None = None which works fine

tender cradle
#

Just by that? Ok that's a bug then, it should be equivalent, thanks for letting us know ๐Ÿ™‚

undone forge
#

No other changes to get that working

tender cradle
#

Ok, so I didn't know about this:

>>> get_origin(str | None)
<class 'types.UnionType'>
>>> get_origin(Optional[str])
typing.Union
#

One is a UnionType, the other is a Union ๐Ÿ˜

undone forge
#

I didn't know about that either