[Python-Dev] Deprecating locals() (was Re: nested scopes and global: some corner cases)

Tim Peters tim.one@home.com
Mon, 28 May 2001 19:42:05 -0400


[Guido]
> Actually, I intend to deprecate locals().  For now, globals() are
> fine.  I also intend to deprecate vars(), at least in the form that is
> equivalent to locals().

[Fred L. Drake, Jr.]
>   Nothing has happened on this front yet.  Should I add deprecation
> notes to the docummentation while Guido is on vacation, or wait to ask
> him when he gets back?  Or was this matter resolved when I wasn't
> paying attention?

I advise continuing to ignore it.  Nothing was resolved, and to judge from a
trial balloon I floated on c.l.py at the time, it's not a deprecation that
will be greeted with enthusiasm.  The problems range from people doing

def f(...):
     ...
     print "..." % locals()

to people mutating locals() at module level because they simply don't
understand that globals() is the same (but correct) thing to use there.

Due to the first example, and as Samuele may <wink> have already suggested,
we at least need to implement a mapping object capturing name bindings
before we can even think about deprecating locals() for real.