Tom Ritchford
Jul 3, 2024

--

Why, specifically, would one wish to prohibit calling that function on some value for which it would work, and give a correct answer?

Indeed, passing a list gives a wrong impression - that the function might want to mutate the list at some point.

Absent some very good reason, a reason which is not explicated in the code or the text, PEP 483 is definitive: "Choose the most general type for every argument, and the most specific type for the return value."

I strongly recommend reading that whole document to get an idea of the philosophy behind Python type hints, where the underlying ethos is to be as unrestrictive as possible while still enforcing correctness.

--

--

No responses yet