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
Metadata
Release files for dis-magic 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dis-magic-1.0.0.tar.gz | 2.3 kB | Without provenance | Details for dis-magic-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dis_magic-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for dis_magic-1.0.0-py3-none-any.whl |
Total release size: 4.6 kB
Release files / dis-magic-1.0.0.tar.gz
| Download URL | dis-magic-1.0.0.tar.gz |
|---|---|
| Size | 2.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14b271b8044430b16f20c3fefa5e1f2645eb0f2ede6962b085d96b8597388eec
|
|
BLAKE2b-256 checksum How to use checksums |
a91791ff1e28bc580a13520fdb4b0c865456653c6c86657032ebf3a44eda26fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / dis_magic-1.0.0-py3-none-any.whl
| Download URL | dis_magic-1.0.0-py3-none-any.whl |
|---|---|
| Size | 2.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a30dc4ab145868aa1676e5f6f0561e73ca794e6ca10545ad90ed77fcb66ef31
|
|
BLAKE2b-256 checksum How to use checksums |
13a29119d75e55e0ac39414f255f0c3edc674074ab0c5d55f1d5bb5c36828167
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for dis-magic 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.