Comment Comment by posix_monad 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. parent posix_monad 2 years ago
For example:
I guess this is to make scripting more forgiving.In typical typed languages, you would have two functions instead:
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: Not an experienced Python dev, so curious how this works in practice.