Peter said:
Fredrik Lundh wrote:
Fixing the exception type doesn't help if the change is implemented like the
constancy of None:
.... None
.... except NameError:
.... None = object()
....
SyntaxError: assignment to None
Aargghh, so the knowledge of None's constancy appears to extend into the
syntax analysis. Damn, that means my last posting was wrong as well.
Should have checked this all out in 2.4 before asserting things that
weren't true, I suppose.
Interestingly the same error occurs even when attempting sideways access:
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.SyntaxError: assignment to None
I'm not sure that I actually agree with the classification of this as a
syntax error - there's actually nothing wrong with the syntax at all in
either of these two cases.
Another workaround seems viable:
globals()["None"] = "Evil Nun"
None
Clearly the behavior of None has been fairly radically altered if you
can't see a None in globals any more:
Python 2.3.4 (#53, Oct 18 2004, 20:35:07) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> globals()["None"] = "An Evil String"
>>> None
'An Evil String'
Of course this is all in line with the intention that programmatic
references to None should always pick up the singleton instance of type
NoneType.
It's also quite interesting that the Python 2.4 documentation actually
says (in section 2.5 of the Python Library reference" that False and
True are constants, when they clearly aren't "as constant as None":
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
regards
Steve