[Python-Dev] Compiler treats None both as a constant and variable
Guido van Rossum
Sun, 30 Mar 2003 14:02:38 -0500
> >>> def f():
> >>> dis(f)
> 2 0 LOAD_GLOBAL 0 (None)
> 3 POP_TOP
> 4 LOAD_CONST 0 (None)
> 7 RETURN_VALUE
> >>> None = 1
> <stdin>:1: SyntaxWarning: assignment to None
> >>> f() == None
> Is this a bug?
Yes, assigning to None is a bug. :-)
> Should the compiler use the GLOBAL in both places?
No, not until we've officially changed the rules.
> Or, is it reasonable to use CONST in both places?
No, not until assigning to None is an error rather than a warning.
This will have to wait until at least 2.4 -- the warning is new in
--Guido van Rossum (home page: http://www.python.org/~guido/)