-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-26213: Document _UNPACK bytecodes and BUILD_MAP changes #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Doc/library/dis.rst
Outdated
.. versionadded:: 3.5 | ||
|
||
|
||
.. opcode:: BUILD_MAP_UNPACK_WITH_CALL (count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -772,8 +813,11 @@ All of the following opcodes use their arguments. | |||
|
|||
.. opcode:: BUILD_MAP (count) | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a nitpick, but different PEPs recommend to use a double space after sentence ending period.
Doc/library/dis.rst
Outdated
so that the dictionary holds ``count`` entries: | ||
``{..., TOS3: TOS2, TOS1: TOS}``. | ||
|
||
.. versionchanged:: 3.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention what is changed.
Doc/library/dis.rst
Outdated
@@ -723,6 +723,47 @@ All of the following opcodes use their arguments. | |||
are put onto the stack right-to-left. | |||
|
|||
|
|||
.. opcode:: BUILD_TUPLE_UNPACK (count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "merges" is more appropriate term than "joins".
Thanks! I have implemented new comments in another commit. |
Fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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