<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 9, 2015, at 4:06 PM, Neil Girdhar <<a href="mailto:mistersheik@gmail.com" class="">mistersheik@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class="">Hello all,<div class=""><br class=""></div><div class="">The updated PEP 448 (<a href="https://www.python.org/dev/peps/pep-0448/" target="_blank" class="">https://www.python.org/dev/peps/pep-0448/</a>) is implemented now based on some early work by Thomas Wouters (in 2008) and Florian Hahn (2013) and recently completed by Joshua Landau and me.</div><div class=""><br class=""></div><div class="">The issue tracker <a href="http://bugs.python.org/issue2292" target="_blank" class="">http://bugs.python.org/issue2292</a> has a working patch. Would someone be able to review it?</div><div class=""><br class=""></div></div></div></div></blockquote><br class=""></div><div><div>I just skimmed over the PEP and it seems like it’s trying to solve a few different things:</div><div><br class=""></div><div>* Making it easy to combine multiple lists and additional positional args into a function call</div><div>* Making it easy to combine multiple dicts and additional keyword args into a functional call</div><div>* Making it easy to do a single level of nested iterable "flatten".</div><div><br class=""></div><div>Looking at the syntax in the PEP I had a hard time detangling what exactly it was doing even with reading the PEP itself. I wonder if there isn’t a way to combine simpler more generic things to get the same outcome.</div><div><br class=""></div><div>Looking at the "Making it easy to combine multiple lists and additional positional args into a function call" aspect of this, why is:</div><div><br class=""></div><div>print(*[1], *[2], 3) better than print(*[1] + [2] + [3])?</div><div><br class=""></div><div>That's already doable in Python right now and doesn't require anything new to handle it.</div><div><br class=""></div><div>Looking at the "making it easy to do a single level of nsted iterable 'flatten'"" aspect of this, the example of:</div><div><br class=""></div><div>>>> ranges = [range(i) for i in range(5)]</div><div>>>> [*item for item in ranges]</div><div>[0, 0, 1, 0, 1, 2, 0, 1, 2, 3]</div><div><br class=""></div><div>Conceptually a list comprehension like [thing for item in iterable] can be mapped to a for loop like this:</div><div><br class=""></div><div>result = []</div><div>for item in iterable:</div><div> result.append(thing)</div><div><br class=""></div><div>However [*item for item in ranges] is mapped more to something like this:</div><div><br class=""></div><div>result = []</div><div>for item in iterable:</div><div> result.extend(*item)</div><div><br class=""></div><div>I feel like switching list comprehensions from append to extend just because of a * is really confusing and it acts differently than if you just did *item outside of a list comprehension. I feel like the itertools.chain() way of doing this is *much* clearer.</div><div><br class=""></div><div>Finally there's the "make it easy to combine multiple dicts into a function call" aspect of this. This I think is the biggest thing that this PEP actually adds, however I think it goes around it the wrong way. Sadly there is nothing like [1] + [2] for dictionaries. The closest thing is:</div><div><br class=""></div><div>kwargs = dict1.copy()</div><div>kwargs.update(dict2)</div><div>func(**kwargs)</div><div><br class=""></div><div>So what I wonder is if this PEP wouldn't be better off just using the existing methods for doing the kinds of things that I pointed out above, and instead defining + or | or some other symbol for something similar to [1] + [2] but for dictionaries. This would mean that you could simply do:</div><div><br class=""></div><div>func(**dict1 | dict(y=1) | dict2)</div><div><br class=""></div><div>instead of</div><div><br class=""></div><div>dict(**{'x': 1}, y=2, **{'z': 3})</div><div><br class=""></div><div>I feel like not only does this genericize way better but it limits the impact and new syntax being added to Python and is a ton more readable.</div><div class=""><br class=""></div></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">---</div><div class="">Donald Stufft</div><div class="">PGP: 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA</div></div></div>
</div>
<br class=""></body></html>