On 29 Dec 2013 09:44, "Steven D'Aprano" <steve@pearwood.info> wrote:
>
> On Sat, Dec 28, 2013 at 11:55:19AM -0800, Andrew Barnert wrote:
> > On Dec 28, 2013, at 4:27, Steven D'Aprano <steve@pearwood.info> wrote:
>
> > > Or perhaps there are
> > > two pure-Python modules with the same API, and you're not sure which is
> > > installed. This issue is bigger than just C-accelerators in the CPython
> > > standard library. It applies any time you have two or more alternatives
> > > with the same API, a preferred module and an fallback module. E.g.
> > > readline in the stdlib, versus pyreadline, a third-party Windows port.
> >
> > There are maybe three such examples that people use regularly. Is that
> > enough to warrant a change in the language?
>
> There's only one *common* example of augmented assignment, x += 1, but
> that was enough to justify a whole raft of new syntax, += -= *= |= etc
> because the *idiom* of "x = x op arg" is common.
>
> What matters is not the specific examples of which modules get used in
> this way, but that the idiom of
>
> try:
>     import this
> except ImportError:
>     import that as this
>
> is common, not the specific values of this/that. I do not expect that
> the idiom of having a fallback module when the preferred module isn't
> available will ever disappear, simply because there are too many
> circumstances in which it comes up.
>
> Having said that, Nick's comments strike me as critical. "import this or
> that" doesn't buy us anything that can't already be solved in other
> ways. If it were easy to add, then perhaps it would be justified. But
> the implementation of import is already gnarly and hard to maintain (so
> I'm told), so adding more complexity to it for something which is purely
> syntactic sugar is probably not the best thing to do.

I suspect this would actually be pretty easy to implement (for a given definition of easy, since we'd likely handle it in the bytecode generation phase). However, it would still make the import statement even harder to fully comprehend than it already is, which is actually quite a notable achievement :)

Cheers,
Nick.
>
> Maybe in Python 4000 :-)
>
>
> --
> Steven
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/