[Python-Dev] Unexpected bytecode difference

Joe Jevnik jjevnik at quantopian.com
Fri Jan 19 19:05:43 EST 2018


As a general rule, you should not expect the bytecode to be the same
between different versions of CPython, including minor version changes. For
example, the instructions for dictionary literals are different in 3.4,
3.5, and 3.6.

On Fri, Jan 19, 2018 at 6:54 PM, Victor Stinner <victor.stinner at gmail.com>
wrote:

> Python bytecode format changed deeply in Python 3.6. It now uses
> regular units of 2 bytes, instead of 1 or 3 bytes depending if the
> instruction has an argument.
>
> See for example https://bugs.python.org/issue26647 "wordcode".
>
> But CALL_FUNCTION bytecode also evolved.
>
> Victor
>
> 2018-01-20 0:46 GMT+01:00 Alexander Belopolsky <
> alexander.belopolsky at gmail.com>:
> > I have encountered the following difference between Python 3 and 2:
> >
> > (py3)
> >>>> compile('xxx', '<>', 'eval').co_code
> > b'e\x00S\x00'
> >
> > (py2)
> >>>> compile('xxx', '<>', 'eval').co_code
> > 'e\x00\x00S'
> >
> > Note that 'S' (the code for RETURN_VALUE) and a zero byte are swapped
> > in Python 2 compared to Python 3.  Is this change documented
> > somewhere?
> > _______________________________________________
> > Python-Dev mailing list
> > Python-Dev at python.org
> > https://mail.python.org/mailman/listinfo/python-dev
> > Unsubscribe: https://mail.python.org/mailman/options/python-dev/
> victor.stinner%40gmail.com
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
> joe%40quantopian.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180119/5955a744/attachment.html>


More information about the Python-Dev mailing list