[Python-Dev] Can Python implementations reject semantically invalid expressions?
Craig Citro
craigcitro at gmail.com
Fri Jul 2 08:55:10 CEST 2010
> This question has an easy answer - can you possibly tell the difference?
>
Ok, I'm obviously being silly here, but sure you can:
>>> dis.dis("raise TypeError()")
0 <114> 26977
3 <115> 8293
6 IMPORT_STAR
7 SETUP_EXCEPT 25968 (to 25978)
10 <69>
11 <114> 28530
14 <114> 10536
>>> dis.dis("1 + '1'")
0 <49>
1 SLICE+2
2 STORE_SLICE+3
3 SLICE+2
4 <39>
5 <49>
6 <39>
That said, I agree with the point you're making -- they have the same
semantics, so you should be fine substituting one for the other.
Honestly, though, I'd come down on the side of letting the compiler
raise an error -- while I understand that it means you have
*different* behavior, I think it's *preferable* behavior.
-cc
More information about the Python-Dev
mailing list