- Notifications
You must be signed in to change notification settings - Fork6
JupyterLab extension to explore CPython Bytecode
License
jtpio/jupyterlab-python-bytecode
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
JupyterLab extension to inspect Python Bytecode.
Try the extension in your browser with Binder:
- JupyterLab 1.0+
ipykernelorxeus-python
To install JupyterLab:
conda install -c conda-forge jupyterlab
jupyter labextension install jupyterlab-python-bytecode
- Live Bytecode preview
- Choose the kernel for a file (if not already started). This allows comparing the bytecode output for different versions of Python.
- Check the
Avanced Settings Editorto tweak some of the settings
SeeCONTRIBUTING.md to know how to contribute and setup a development environment.
Disassembling the Python code is done by connecting to a kernel, and sending the following code for evaluation from the lab extension:
importdisdis.dis(code_to_evaluate)
As mentioned in the documentation, there is not guarantee on the stability of the bytecode across Python versions:
Bytecode is an implementation detail of the CPython interpreter. No guarantees are made that bytecode will not be added, removed, or changed between versions of Python. Use of this module should not be considered to work across Python VMs or Python releases.
For example, if the Python file contains the following lines:
importmathprint(math.pi)
The following code will be sent to the kernel for evaluation:
importdisdis.dis("""import mathprint(math.pi)""")
Which will return (example for CPython 3.6.6):
10LOAD_CONST0 (0)2LOAD_CONST1 (None)4IMPORT_NAME0 (math)6STORE_NAME0 (math)38LOAD_NAME1 (print)10LOAD_NAME0 (math)12LOAD_ATTR2 (pi)14CALL_FUNCTION116POP_TOP18LOAD_CONST1 (None)20RETURN_VALUE
If you have several versions of Python installed on your machine (let's say in different conda environments), you can use the extension to check how the bytecode might differ.
The following example illustrates the introduction of the newCALL_METHOD opcode introduced in CPython 3.7:
Original example fromDisassembling Python Bytecode, by Peter Goldsborough
About
JupyterLab extension to explore CPython Bytecode
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.


