[Python-ideas] Add from __experimental__ import bla [was: Should we move to replace re with regex?]

ron3200 ron3200 at gmail.com
Tue Aug 30 05:02:03 CEST 2011

On Mon, 2011-08-29 at 18:22 -0700, Bruce Leban wrote:

> Unlike __future__ the API is unstable and therefore code that works
> with today's __experimental__ may fail tomorrow. If the API changes in
> an incompatible way, we would probably prefer that the import fail
> rather than succeed with random results. Therefore, I would propose a
> mechanism to support this, perhaps something like
>         from __experimental__ import regex {2,3,4} as re
> which means import the regex module version 2, 3 or 4. A later version
> will be imported only if it is an expansion, i.e., compatible with all
> previous APIs and differs only in containing new features. If the
> version set is omitted from the import it's treated as {1} so that
> dealing with this is only necessary for those modules which do change
> in incompatible ways.
> In general, checking for specific capabilities rather than version
> numbers is more robust but in this case, perhaps multiple versions of
> experimental APIs will be discouraged making that less necessary. But
> we could allow strings specifying required features in the version
> set. Note that the reason for allowing import with more than one
> version number is to handle the case when a new version is available
> but the differences are in parts of the API that don't impact the
> application.

Encouraging limited use of __experimental__ may be good.  If it looks
like there are going to be more than two three different combinations,
then it is likely too soon to even be in __experimental__.  It probably
needs more thought still. 

One possibility would be to have experimental features be of the form,
which is better? (a or b).

Then you could try things out and save timings and test results in a
fairly straight forward way.

results = {}

for x in 'ab':
    from __experimental__[x] import regex as re
    <do stuff with re and save some data about it>

for x in 'ab':

I can think of a few issues with this.  Like how long do things live in
__experimental__?  Can the letters be reused, or should new letters be
used each time?  Is "from __experimental__[x] import feature" better or
worse than "from __experimental__ import feature[x]"?  And do subscripts
even work in import statements?

Then again,  maybe version #'s would work better?

Having a way to ask __experimental__ what is has and use that to do the
importing could make doing some things easier.




More information about the Python-ideas mailing list