PEP 646: Explain the results of the new grammar/compiler change#2189
PEP 646: Explain the results of the new grammar/compiler change#2189gvanrossum merged 2 commits intopython:mainfrom mrahtz:pep646
Conversation
|
Looking at the bytecodes, you could use |
|
This looks good to me, especially if we follow @TeamSpen210's suggestion - it seems handy to verify that only length-1 iterators are ever used this way. You're right that it's an implementation detail as long as the AST and visible behavior are nailed down, so if reviewers of the cpython code have other ideas that should also be okay. We should be able to use the same approach for unpacking in callable syntax. |
* Don't link to the current draft implementation * Clarify the code emitted for *args: *Ts now we've switched to the UNPACK_SEQUENCE bytecode in CPython * Update the examples of nonsensical *args annotations
|
Thanks for the excellent suggestion, @TeamSpec210! I've switched to And thanks, Guido, for the feedback! I've made the changes you suggested. |
@pradeep90 @gvanrossum @stroxler
I'm still not entirely sure that having the compiler emit the equivalent of
next(iter(Ts))for*args: *Tsis the best solution. The alternatives I can think of are:[*Ts][0](uglier, but the bytecode ends up being a little simpler)Ts._unpacked(less ugly, but less consistent with other uses of the star operator)Having said that, I also think
next(iter(Ts))is Good Enough (tm) - and in the first place (I think?) it's not too critical an issue because it's an implementation detail. So happy to discuss this, but also happy not to discuss this :)