[Python-Dev] Re: Prospective Peephole Transformation

Raymond Hettinger python at rcn.com
Fri Feb 18 16:15:04 CET 2005


> > Raymond then
> translated
> >
> >     for x in [1,2,3]:
> >
> > to
> >
> >     for x in frozenset([1,2,3]):

That's not right.  for-statements are not touched.


> I may be missing something here (didn't follow the whole thread) but
> those two are not functionally equal.
> The docstring on frozenset sais "Build an immutable unordered
collection."
> So there's no guarantee that the elements will return from the
> frozenset iterator in the order that you constructed the frozenset
with,
> right?

Only contains expressions are translated:

    "if x in [1,2,3]"

currently turns into:

    "if x in (1,2,3)"

and I'm proposing that it go one step further:

    "if x in Seachset([1,2,3])"

where Search set is a frozenset subtype that doesn't require x to be
hashable.  Also, the transformation would only happen when the contents
of the search are all constants.


Raymond


More information about the Python-Dev mailing list