Deep inspection of Python objects
Project description
🙀 WAT Inspector
Deep inspection of Python objects.
WAT is a powerful inspection tool that allows you to delve into and examine unknown objects at runtime.
"Wat" is a variant of the English word "what" that is often used to express confusion or disgust
If you find yourself deep within the Python console, feeling dazed and confused,
wondering "WAT? What's that thing?",
that's where the wat
inspector comes in handy.
Start the Python Interpreter (or attach to one) and execute wat / object
on any object
to investigate its
type, formatted value, variables, methods, parent types, signature,
documentation, and even its source code.
Alternatively, you can use wat(object)
syntax.
Import
Insta-Load
If you want to quickly debug something, you can use this inspector without installing anything, in the same session.
Load it on the fly by pasting this snippet to your Python interpreter:
import base64, zlib
code = b'eJzdW+tu20YW/p+nILw/RDqs1m72AqhVdt3ETQOkzcJ1Nwgcg6DEkc2GIgWSiu0VBPQh9hn2wfZJ9lzmTlKSmy6wWAOWyJlzvplzmTNnLlrU1TLI0jadF2nTiCbIl6uqbk3RE1mQl81KzNsgbYKmzRL5qmorTVcL9dQ8NE8WCN8+rPLyRiGflQ9x8DKft3HwJm/g8+2qzasyLeLg8mEl4uB1K+p0VsDTTyVUPPmr6Qt9Bq+57RdVuchvJk8C+GtuAXoSzKqqoPdsXWaitgrKKqvmjVVQVOWN9TqvMiFfh9o7a9s6n61bwU2W6RI4mramt09psYZXEI5eQWR4Q3kYPS0KFGlXD1d1/iltbZImvynTdl1DmdLRFbR3zfzV3C/OxEKZKVlU9TJtQyKtZj9Tz2J6O459jQXT4Nu0aETc6ZhbY+vQrTHKdMuNVt1yUIdfHAVfPEdtTiQj2hZqHVuH1Okpfcayo1P+CqoaUWPZySl/xdSzKX5oAuzTFD9kScQ6WrerNegDXZK0CW1fsabhLSHzQpHUK7+HoFjmrsVK0pBHACGWmPp8YZEE0ykSUS32wa1JoCpfJfOqqOpQNx2xWkxPx+lqJcosXIw2P16+f3OefHPx+tV3l8k3b34633JPNhfnP55fboONRtmOuDsCNP4oQLTLMNyBICinQbHrtxujg62kkNjYGA4mS/f4GtIHatA2387maUg6QmCJameV1qJsG6sZLiG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9bKqL0yaRDZMH2PF8ksnX98cjiEOgiU3DwifcXJHcRO/p2JgjktjXWHyf+5ymRA+ZU6G85CJ3TPbUeW23Oi2r+1vyHGrbuhj5pUuYT89ZnZBcEfBIX2fT31GxtNcoW81279jnvE9hViXjKYVfDABWLrVymGWAo4eIv4kReISSHBdPTh5Nmzq5Pl6IkNSuk+Vpzqipevv9elX+rSi/OXuvTkq2enHo5Tf2rX09abzfqlz+pSnNoULJ7N/czn9khOHRL8jZzF/Aef2SE4tQnkjVSb+4+68sX7M0ekP+mad9+9vnSa/LOliLP3RrFU8x82JMIP'
exec(zlib.decompress(base64.b64decode(code)).decode(), globals())
Now you can use wat
object.
[!Warning] Before executing Insta-Load snippet, it's recommended to verify what you're about to run. If you feel uncomfortable, you can either:
- Verify what's inside the extracted code beforehand:
print(zlib.decompress(base64.b64decode(code)).decode())- Paste the content of inspection.py into your interpreter. It has the same effect.
- Install package with pip and review the code.
Install with pip
Alternatively, install wat-inspector package and import inspection tool from wat module:
pip install wat-inspector
import wat
Usage & modifiers
wat
object can quickly inspect things
by using the division operator (for faster typing without parentheses).
A short syntax wat / object
is equivalent to wat(object)
.
You can call wat.modifiers / object
with the following modifiers:
.short
or.s
to hide attributes (variables and methods).long
to show non-abbreviated values and documentation.dunder
to display dunder attributes.code
to reveal the source code of a function, method, or class.nodocs
to hide documentation for functions and classes.all
to include all available information.ret
to return the inspected object.str
to return the output string instead of printing.gray
to disable colorful output in the console
You can chain modifiers, e.g. wat.long.dunder.nodocs / object
.
Call wat.locals
or wat()
to inspect locals()
variables.
Call wat.globals
to inspect globals()
variables.
Type wat
in the interpreter to learn more about this object itself.
There are several alternative syntaxes that are equivalent. Choose the one that works best for you:
wat.short / 'foo' # fast typing
wat.short('foo')
wat('foo', short=True) # natural Python syntax
'foo' | wat.short # Unix piping
Use Cases Examples
Determine type
In a dynamic typing language like Python, it's often hard to determine the type of an object. WAT Inspector can help you with that by showing the name of the type with the module it comes from.
>>> wat.short / (1,)
value: (1,)
type: tuple
len: 1
>>> wat.short / {None}
value: {None}
type: set
len: 1
>>> wat.short / user
str: admin
repr: <User: admin>
type: django.contrib.auth.models.User
parents: django.contrib.auth.models.AbstractUser, django.contrib.auth.base_user.AbstractBaseUser, django.contrib.auth.models.PermissionsMixin, django.db.models.base.Model, django.db.models.utils.AltersData
Now that you've identified the actual type, you can put the type annotations in your code to reduce the confusion.
Look up methods
Listing methods, functions and looking up their signature is extremely beneficial to see how to use them. Plus, you can read their docstrings.
wat / 'stringy'
Use wat.long
if you want to see full doscstrings.
Discover function's signature
See the docstrings and the signature of a function or a method to see how to use it.
wat / str.split
Look up attributes
List the attribues and their types to see what's really inside the inspected object.
wat / re.match('(\d)_(.*)', '1_title')
Explore modules
One of the use cases is to explore modules. For instance you can list functions, classes and the sub-modules of a selected module.
import pathlib
wat / pathlib
Then, you can navigate further, e.g. wat / pathlib.fnmatch
.
Explore dunder attributes
By default, WAT Inspector hides attributes starting with __
. Use wat.dunder
to see them.
wat.dunder / {}
Review the code
Look up the source code of a function to see how it really works.
import re
wat.code / re.match
Prettify unreadable collections
import sys
wat.s / sys.modules
This will give you a nicely formatted, indented output, even for nested dictionaries or lists.
Debug with breakpoint
You can use Python's breakpoint()
keyword to launch an interactive debugger in your program:
logger.debug('init')
x = {'what is it?'}
breakpoint()
logger.debug('done')
(Pdb) import wat # or paste insta-load snippet
(Pdb) wat / x # inspect local variable
...
(Pdb) c # continue execution
Look up local and global variables
wat.locals
# Local variables:
# __annotations__: dict = {}
# __builtins__: module = <module 'builtins' (built-in)>
# __doc__: NoneType = None
# __loader__: type = <class '_frozen_importlib.BuiltinImporter'>
# __name__: str = '__main__'
# __package__: NoneType = None
# __spec__: NoneType = None
# wat: wat.inspection.inspection.Wat = <WAT Inspector object>
wat.globals
# Global variables:
# ...
Learn Python
With these snippets you can better understand Python internals.
wat.s / reversed([])
# value: <list_reverseiterator object at 0x76749d1cb400>
# type: list_reverseiterator
x = (1 << 53) + 1
wat.s / x
# value: 9007199254740993
# type: int
wat.s / (x + 1.0)
# value: 9007199254740992.0
# type: float
x = float("nan")
wat.s / {x, x, float(x), float(x), float("nan"), float("nan")}
# value: {nan, nan, nan}
# type: set
# len: 3
wat.s / 1 ** -1
# value: 1.0
# type: float
from typing import List
wat.s / List[str]
# value: typing.List[str]
# type: typing._GenericAlias
# parents: typing._BaseGenericAlias, typing._Final
# signature: def List(*args, **kwargs)
wat.s / list[str]
# value: list[str]
# type: types.GenericAlias
# signature: def list(*args, **kwargs)
wat(str | None)
# value: str | None
# type: types.UnionType
Explore Python built-ins:
wat / __builtins__
wat / ...
# value: Ellipsis
# type: ellipsis
Environment variables
WAT_COLOR="false"
to disable colorful output in the console.WAT_COLOR="true"
to enforce colorful outputs even in non-tty environment.
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
File details
Details for the file wat_inspector-0.3.1.tar.gz
.
File metadata
- Download URL: wat_inspector-0.3.1.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 368e481fd00ecf8e65b83a3934d469f3130594bcf288b593e8be5ff2230c9fa9 |
|
MD5 | 4aa8834c272a49ee5c1904ef02f9f984 |
|
BLAKE2b-256 | d08e287d2ab90ffa61f554922fc5b61f6e6c801be773d769deb132b170b7e966 |
File details
Details for the file wat_inspector-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: wat_inspector-0.3.1-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cc5f7c739e7c44b7a12c7d5476c31df3204eb93450ecef809dde5a19cc57de0 |
|
MD5 | 9dd451f3714c6ddae1eb0dd8d06dcd92 |
|
BLAKE2b-256 | 73b2ce6a3944b403bc5dea98a615a2c9ef8bf70fb4be45aaba46fcd8e0073238 |