IPython extension allowing visualizing bytecode of cell using magic
Project description
This allows you to visualize the bytecode of a cell in IPython upon running it.
Installation
pip3 install dis-magic
To manually load, run the following in your IPython prompt:
%load_ext dis_magic
To automatically load, add the following to your IPython configuration file:
c = get_config()
c.InteractiveShellApp.extensions.append('dis_magic')
Usage
Verifying Python follows PEMDAS:
In [6]: %dis foo = 6 ** 2 + 6
1 0 LOAD_CONST 0 (42)
2 STORE_NAME 0 (foo)
4 LOAD_CONST 1 (None)
6 RETURN_VALUE
You can use it in a cell too:
In [4]: %%dis
...:
...: def fibonacci(n: int) -> int:
...: if n <= 1: return 1
...: return fibonacci(n - 2) + fibonacci(n - 1)
...:
2 0 LOAD_NAME 0 (int)
2 LOAD_NAME 0 (int)
4 LOAD_CONST 0 (('n', 'return'))
6 BUILD_CONST_KEY_MAP 2
8 LOAD_CONST 1 (<code object fibonacci at 0x111457b30, file "<dis>", line 2>)
10 LOAD_CONST 2 ('fibonacci')
12 MAKE_FUNCTION 4 (annotations)
14 STORE_NAME 1 (fibonacci)
16 LOAD_CONST 3 (None)
18 RETURN_VALUE
Disassembly of <code object fibonacci at 0x111457b30, file "<dis>", line 2>:
3 0 LOAD_FAST 0 (n)
2 LOAD_CONST 1 (1)
4 COMPARE_OP 1 (<=)
6 POP_JUMP_IF_FALSE 12
8 LOAD_CONST 1 (1)
10 RETURN_VALUE
4 >> 12 LOAD_GLOBAL 0 (fibonacci)
14 LOAD_FAST 0 (n)
16 LOAD_CONST 2 (2)
18 BINARY_SUBTRACT
20 CALL_FUNCTION 1
22 LOAD_GLOBAL 0 (fibonacci)
24 LOAD_FAST 0 (n)
26 LOAD_CONST 1 (1)
28 BINARY_SUBTRACT
30 CALL_FUNCTION 1
32 BINARY_ADD
34 RETURN_VALUE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dis-magic-1.0.0.tar.gz.
File metadata
- Download URL: dis-magic-1.0.0.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14b271b8044430b16f20c3fefa5e1f2645eb0f2ede6962b085d96b8597388eec
|
|
| MD5 |
0c6d63741430fee8453c651d7bf752da
|
|
| BLAKE2b-256 |
a91791ff1e28bc580a13520fdb4b0c865456653c6c86657032ebf3a44eda26fd
|
File details
Details for the file dis_magic-1.0.0-py3-none-any.whl.
File metadata
- Download URL: dis_magic-1.0.0-py3-none-any.whl
- Upload date:
- Size: 2.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a30dc4ab145868aa1676e5f6f0561e73ca794e6ca10545ad90ed77fcb66ef31
|
|
| MD5 |
cd4b74690274266bea9019f3abfce5b1
|
|
| BLAKE2b-256 |
13a29119d75e55e0ac39414f255f0c3edc674074ab0c5d55f1d5bb5c36828167
|