DEV Community

Discussion on: Literals and overloading in Python

Collapse
 
aktentasche profile image
Jonas Manthey

Why not use an Union for the return type

Collapse
 
finloop profile image
Piotr

In the first example Union is the return type. As Literal["all", 1] is union of Literal[all] and Literal[1]. But the warning about types still persists.

My point is that with overloading and Literals/types you can precisely specify return types of functions. Something that Unions cannot do.