[Python-Dev] Fast access to __builtins__

Jack Diederich jack@performancedrivers.com
Thu, 27 Mar 2003 22:21:10 -0500

On Thu, Mar 27, 2003 at 07:35:20PM -0500, Raymond Hettinger wrote:
[Raymond proposed this pythonic version of a pragma]
> __fastbuiltins__ = True  # optimize all subsequent defs in the module
> [Jack Diederich]
> > The downside of a pragma module or
> > keyword would be what people try to add to it later.
> Ideally, enabling the pragma would also trigger warnings when the
> module shadows a builtin.

I was thinking that a first-class keyword like
pragma no_shadow_builtins
would give people a hook to suggest all kinds of nastiness in the future.
In your pythonness your suggestion avoided this entirely.

We are talking about a very per-module thing, and author's intent.
As a progression, how about a subclass of dictionaries that implement
warn-on-assign and error-on-assign properties.  Having a subclass of dicts
specifically for symbol tables has been suggested before and has a wide
variety of benefits[1].  This is a good example.


[1] benefits of a specific 'symtab' type that derives from dict
 (all variations on 'one stop shop for optimizations')
 * string-only
 * assign-once (builtins)
 * cached lookups