Today, i lost a lot of time fixing a stupid error in my code. Very simplified, the problem was this:
def f():
return 2
2 == f
I forgot to write the parenthesis in the sentence, so I compared a pointer function with a number.
Ok, my question:
Is there any way to change the interpreter to be more stricted with the code? Show more warnings for example…
Thanks ^^
One of the disadvantages of working with a dynamically typed language is that the language environment has very little or no information about the types of things when it sees a statement, so it can issue no warning when it sees it, only when the statement is executed.
For various reasons it’s very convenient for all types to be able to be compared to all others for equality. It makes heterogeneous containers much easier to write. So comparing a function to an integer is a defined thing to do, and since that can happen in so many useful cases, the interpreter can’t really give you a warning about it at runtime. And while the construct is questionable, it can’t give you a warning when it sees the statement (as opposed to executing it) because then it doesn’t have the necessary type information to issue the warning.