[Patches] [ python-Patches-768442 ] Warning 'assignment shadows builtin' __builtins__ fix
SourceForge.net
noreply@sourceforge.net
Wed, 16 Jul 2003 10:30:27 -0700
Patches item #768442, was opened at 2003-07-09 13:13
Message generated for change (Comment added) made by nascheme
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=768442&group_id=5470
Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Troels Therkelsen (troelst)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Warning 'assignment shadows builtin' __builtins__ fix
Initial Comment:
Python 2.3b2 (#1, Jun 30 2003, 13:04:39)
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> import sys, new
>>> d = {'__builtins__':{}}
>>> d['mod'] = new.module('mod')
>>> d['mod'].__builtins__ = d['__builtins__']
>>> exec "mod.reload = 42" in d
<string>:1: DeprecationWarning: assignment shadows
builtin
>>> d['sys'] = sys
>>> exec "print sys._getframe().f_builtins" in d
{}
Surely, the DeprecationWarning shouldn't be printed if
you use __builtins__ to explicitly define your own builtins
dict? I mean, the 'reload' name in this case is an
unknown name until it is defined in mod.
The submitted patch fixes Objects/moduleobject.c so
that the warning is only done if the module global you're
assigning to exists in f_builtins. The patch is somehwat
naive I admit, and it reuses as much as the old code as
possible. Alternatively, instead of all the work done, one
could just check directly in f_builtins.
----------------------------------------------------------------------
>Comment By: Neil Schemenauer (nascheme)
Date: 2003-07-16 17:30
Message:
Logged In: YES
user_id=35752
No vacation for me. I'll take a crack at it.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2003-07-16 16:10
Message:
Logged In: YES
user_id=6380
Not warning if __builtins__ is overridden sounds like a fine
compromise to me. I believe Neal is on vacation -- who's
going to fix this?
----------------------------------------------------------------------
Comment By: Neil Schemenauer (nascheme)
Date: 2003-07-10 18:21
Message:
Logged In: YES
user_id=35752
I'm not sure what's the right thing to do here. One simple
(I think) solution would be to not warn if __builtins__ are
overridden. We don't want to implement anything too
complicated since the 2.3 is quickly approaching. Hopefully
Guido can give me a clue as to what kind of a solution he
would like to see.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=768442&group_id=5470