[Python-Dev] Can Python implementations reject semantically invalid expressions? (original) (raw)

Craig Citro craigcitro at gmail.com
Fri Jul 2 18:51:08 CEST 2010


But you would be taking a module that will compile and making it uncompilable.

You're absolutely right, and since I definitely don't think that the program "raise TypeError" should cause a CompileError, you could say it's safer to have a simple rule like "vaild syntax => will compile" -- it's probably a slippery slope once you start deciding which bits of semantics raise CompileErrors and which don't.

However, in this particular case, here's a question: why would someone write "return 1 + '1'"? Did they do it knowing what would happen, or because they just didn't realize it was just an error?

Either way, I personally prefer the CompileError -- it helps me catch a stupid mistake if I've made one, and it prevents other people from writing code I find less clear.

My real motive, though, is that I'd like to have more freedom for Python implementations, especially things that let you make more decisions at compile-time. (This is no doubt influenced by the fact that I've spent a lot of time thinking about Cython lately.) In this case, I see it as a win-win -- it gives more freedom to the folks writing the implementation, and (personally) I find it more pleasing as a user. Again, I don't think this particular case allows us to do something awesome behind the scenes with Cython -- but the community starting to consider changes of this ilk would be a big win, I think.

-cc



More information about the Python-Dev mailing list