I find the motivation section very weak.
(I don’t know what Python means in this context, I’m assuming you mean Python functions and methods.)
If you run a type checker, this isn’t true. Maybe you can just run a type checker?
A small segue here. I’ve noticed that the Reddit brigade looks down on Python typing since it’s “optional”. But… As far as I know, statically typed languages don’t generally do runtime validation of function arguments either. One of the main points of types is that they lower overhead at runtime by doing some of the work at type-checking time. If you pass a Java function a list of a million integers, there’s no code that performs a loop checking if each element is actually an integer.
Disregarding the fact that bool
is a subclass of int
and the proposed solutions using isinstance
would definitely allow this, again, if you run a type checker, these errors will not be silently ignored. Why not run a type checker?
That’s neither here nor there.
Taking a step back - checking types statically, where possible, is strictly better than checking them at runtime. Situations where it’s not possible (edge validation) are already covered as well as they can be.
If this feature was added, who exactly would use it and why, and why would it be better than running a type checker? (You know, questions that would be answered by the Motivation section.)