[Python-ideas] + operator on generators
Chris Angelico
rosuav at gmail.com
Sat Jul 1 04:21:29 EDT 2017
On Sat, Jul 1, 2017 at 6:11 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> - So there's then a new conditional import (e.g. in a compat package)? What
>> does this add?
>
> try: chain
> except NameError: from itertools import chain
>
> Two lines, if and only if you both need chain and want to support
> versions of Python older than 3.7.
>
> There's no need to import it if you aren't going to use it.
>
It'd be even simpler. If you want to support <3.7 and 3.7+, you write:
from itertools import chain
At least, I presume it isn't going to be *removed* from itertools.
Promotion to builtin shouldn't break pre-existing code, so the way to
be compatible with pre-promotion Pythons is simply to code for those
and not take advantage of the new builtin.
ChrisA
More information about the Python-ideas
mailing list