Getting struggles to understand : dest:Union[pathlib.Path, str]=None

Someone can recomend to me something to read or where to find data to understant dest:Union[pathlib.Path, str]=None

Union here just means that you can pass it a pathlib.Path OR a string. The =None means it’s optional and if you don’t pass it, then the value of uses will be None (like null in other languages of that helps). You’ll often see parameters using =Some sensible default instead.

In python those things are literally just for documentation. If you use them on your own functions they won’t stop anyone passing in something else so you either need to type check or let it blow up when someone does something stupid, but it makes it clear what you expect someone to pass in.

https://docs.python.org/3/library/typing.html

3 Likes

Thanks! Really helpfull , I’ve just understand it!

1 Like