|
|
|
|
|
by posix_monad
877 days ago
|
|
In Python it's common to have functions whose return types depend on the run-time arguments. For example: def fooify(x):
if isinstance(x, list):
map(fooify, x)
else:
x * 2
I guess this is to make scripting more forgiving.In typical typed languages, you would have two functions instead: fooify : number -> number
fooifyMany : [number] -> [number]
But in the Python community, it's common to have a big function with many behaviors. However, then the type annotations cannot be so precise: fooify : any -> any
Not an experienced Python dev, so curious how this works in practice. |
|
Using you example:
[0] https://docs.python.org/3/library/typing.html#overload