While I understand the idea is to illustrate the point, but the same function can be rewritten like
def add_all(num_list, num): return [n + num for n in num_list]
which is way more generic. And if we imagine the codebase does not use built-in types (eg, num is currency), there will be lots of specialized functions.
It's a good question then whether we aim to be generic (look at Haskell as extreme where one can find suitable functions by its type) or not.
One must be aware type-hints come at the price of limiting reuse because naturally developers start with add_10 , add_100, and hopefully notice add_x can be written, instead of looking at the abstraction axis and get things right from the start.
And some do not naturally write tests or even look their IDE "crying" for type mismatch.
In conclusion, type hinting costs:
- readability
- harder to control genericity
- limiting reuse potentially
Arguably, type-hinting adds some guardrails into the code, but stops short of more advanced type systems. Typing does not precisely catch situations when e.g. output type depends on the input value (then you just hint is with "Any").
Maybe one day Python can come with Hindley-Milner type system / inference so we can stop writing type hints. OTOH I guess AI can do type-hinting pretty closely these days.