[Python-Dev] PEP 359: The "make" Statement

Steven Bethard steven.bethard at gmail.com
Thu Apr 13 21:51:50 CEST 2006


On 4/13/06, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 12:05 PM 4/13/2006 -0600, Steven Bethard wrote:
> >On 4/13/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> > > Steven Bethard wrote:
> > > > I know 2.5's not out yet, but since I now have a PEP number, I'm going
> > > > to go ahead and post this for discussion.  Currently, the target
> > > > version is Python 2.6.  You can also see the PEP at:
> > > >     http://www.python.org/dev/peps/pep-0359/
> > > >
> > > > Thanks in advance for the feedback!
> > >
> >[snip]
> > >
> > > Would it be possible/useful to have a pre-block hook to the callable,
> > > which would provide the dictionary; this dictionary might not be
> > > a proper dictionary (but only some mapping), or it might be
> > pre-initialized.
> >
> >Yeah, something along these lines came up in dicussing using the make
> >statement for XML generation.  You might want to write something like:
> >
> >     make Element html:
> >         make Element head:
> >             ...
> >         make Element body:
> >             ...
> >
> >however, this doesn't work with the current semantics because:
> >
> >(1) dict's are unordered
> >(2) dict's can't have the same name (key) twice
>
> Why not just use 'with' statements for this?  The context gets invoked
> before and after, so it can track any local bindings that occur --
> including the 'as' binding.
>
>     with maker(...) as foo:
>         blah blah
>
> While it's true that frame-locals hacking isn't especially portable, you
> can at least use it to develop your actual use cases for this stuff, and
> then show why the syntax is awkward or doesn't support something.

Sorry, I'm not clear on exactly what you're suggesting.  Are you
suggesting I try to implement the make-statement using context
managers?  Or that I use a context manager to address Martin's
problem?

STeVe
--
Grammar am for people who can't think for myself.
        --- Bucky Katt, Get Fuzzy


More information about the Python-Dev mailing list