[Python-Dev] PEP 408 -- Standard library __preview__ package
Michael Foord
fuzzyman at voidspace.org.uk
Sat Jan 28 03:05:23 CET 2012
On 27/01/2012 20:48, Steven D'Aprano wrote:
> Eli Bendersky wrote:
>
>>> try:
>>> from __preview__ import thing
>>> except ImportError:
>>> import thing
>>>
>>> So no need to target a very specific version of Python.
>>>
>>
>> Yep, this is what I had in mind. And it appeared too trivial to place
>> it in the PEP.
>
> Trivial and wrong.
>
> Since thing and __preview__.thing may have subtle, or major, API
> differences, how do you use it?
>
No, potentially wrong in cases where the APIs are different. Even with
the try...except ImportError dance around StringIO / cStringIO there are
some API differences. But for a lot of use cases it works fine
(simplejson and json aren't *identical*, but it works for most people).
Michael
> try:
> result = thing.foo(a, b, c) + thing.bar(x)
> except AttributeError:
> # Must be the preview version
> result = thing.foobar(a, c, b, x)
>
>
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
More information about the Python-Dev
mailing list