bpo-26213: Document _UNPACK bytecodes and BUILD_MAP changes#238
bpo-26213: Document _UNPACK bytecodes and BUILD_MAP changes#238brettcannon merged 8 commits intopython:masterpython/cpython:masterfrom ilevkivskyi:document-bytecodes-1ilevkivskyi/cpython:document-bytecodes-1Copy head branch name to clipboard
Conversation
Doc/library/dis.rst
Outdated
| .. versionadded:: 3.5 | ||
|
|
||
|
|
||
| .. opcode:: BUILD_MAP_UNPACK_WITH_CALL (count) |
There was a problem hiding this comment.
The semantic is different in 3.5. The lowest byte of oparg is the count of mappings, the relative position of the callable is encoded in the second byte of oparg. Thus needed ".. versionadded:: 3.6".
Or maybe first write a patch that describes 3.5 semantic and change it later in 3.6+ patch.
There was a problem hiding this comment.
I will add the 3.6 semantics in a separate PR. In the new commit I decided to describe the 3.5 semantics.
Doc/library/dis.rst
Outdated
|
|
||
| Pushes a new dictionary object onto the stack. The dictionary is pre-sized | ||
| to hold *count* entries. | ||
| Pushes a new dictionary object onto the stack. Pops ``2 * count`` items |
There was a problem hiding this comment.
This is just a nitpick, but different PEPs recommend to use a double space after sentence ending period.
| so that the dictionary holds ``count`` entries: | ||
| ``{..., TOS3: TOS2, TOS1: TOS}``. | ||
|
|
||
| .. versionchanged:: 3.5 |
There was a problem hiding this comment.
Mention what is changed.
Doc/library/dis.rst
Outdated
| are put onto the stack right-to-left. | ||
|
|
||
|
|
||
| .. opcode:: BUILD_TUPLE_UNPACK (count) |
There was a problem hiding this comment.
Following opcodes create the collection by concatenating/merging several values from the stack. I think it would be better to place their descriptions after BUILD_STRING (which is similar to BUILD_*_UNPACK opcodes but for strings).
Doc/library/dis.rst
Outdated
| .. opcode:: BUILD_TUPLE_UNPACK (count) | ||
|
|
||
| Pops ``count`` iterables from the stack, joins them in a single tuple, | ||
| and pushes the result. |
There was a problem hiding this comment.
It may be worth to mention that it is used for implementing iterable unpacking in tuple displays (see https://docs.python.org/3/whatsnew/3.5.html#pep-465-a-dedicated-infix-operator-for-matrix-multiplication). Example: (*x, *y, *z).
|
Serhiy, thank you for review! I implemented your comments in a new commit. |
Doc/library/dis.rst
Outdated
|
|
||
| Pops ``count`` iterables from the stack, joins them in a single tuple, | ||
| and pushes the result. This bytecode is used for implementing iterable | ||
| unpacking in tuple displays ``(*x, *y, *z)``. |
There was a problem hiding this comment.
Maybe add examples for other opcodes?
[*x, *y, *z]
{*x, *y, *z}
{**x, **y, **z}
Doc/library/dis.rst
Outdated
| Pushes a new dictionary object onto the stack. The dictionary is pre-sized | ||
| to hold *count* entries. | ||
| Pushes a new dictionary object onto the stack. Pops ``2 * count`` items | ||
| so that the dictionary holds ``count`` entries: |
There was a problem hiding this comment.
BUILD_TUPLE and others format the parameter as *count* rather than ``count``.
Doc/library/dis.rst
Outdated
|
|
||
| .. opcode:: BUILD_MAP_UNPACK (count) | ||
|
|
||
| Pops ``count`` mappings from the stack, joins them in a single dictionary, |
There was a problem hiding this comment.
Maybe "merges" is more appropriate term than "joins".
|
Thanks! I have implemented new comments in another commit. |
Fixed. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Now it LGTM. Thank you Ivan. But would be nice if some native speaker take a look.
@briancurtin Could you please also take a look at this? Note that I will update the |
@brettcannon Could you please also take a look at this? Note that I will update the BUILD_MAP_UNPACK_WITH_CALL docs in a separate PR (or maybe I will just update #239) after this is merged. @briancurtin Sorry for disturbing! This was intended for @brettcannon |
Doc/library/dis.rst
Outdated
| .. opcode:: BUILD_TUPLE_UNPACK (count) | ||
|
|
||
| Pops *count* iterables from the stack, joins them in a single tuple, | ||
| and pushes the result. This bytecode is used for implementing iterable |
There was a problem hiding this comment.
Though not technically incorrect, using the sentence "This bytecode is used .." for every case is somewhat repetitive IMO.It might be better to use the same format the other opcodes in the docs use and go for:
Implements iterable unpacking for displays <type_display>
Other than that change, which I believe would be beneficial, the rest look good to me.
Thanks! Fixed this in a new commit. |
|
I tweaked a single word in the PR. Once Travis is green again I'll merge and backport. |
(cherry picked from commit 0705f66)
(cherry picked from commit 0705f66)
|
Thank you Ivan and Brett. |
This needs to be backported to 3.5 and 3.6
This fixes http://bugs.python.org/issue26213
@serhiy-storchaka Please take a look