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.
wat-demo.mp4
If you want to debug something quickly, you don't even need to install anything to use the inspector.
Load it on the fly by pasting this snippet to your Python interpreter:
import base64, zlib
code = b'eJzNWumO20YS/u+naEx+iLJpxRPvASiRd5144hhwkoUz2cCYGRCUSM0wpkiBpGxPtALyEPsM+2D7JFtHH9U8JM1sAsSAR1J31dddR1dXV/eyKlcqiZt4kcd1ndYqW63LqnFND3RDVtTrdNGouFZ1k0T6p+ktLV2Vmm/1bf1gifDN7Torrg3y8+I2VC+yRROq11kNf79fN1lZxHmozm/XaaheNWkVz3P49mMBHQ/+7uZCf9UrHvurslhm19MHCv7VNwA9VfOyzOl3simStBINRZmUi1o05GVxLX4uyiTVP4fGe940VTbfNCkPWcQr4Kibin69j/MN/ATh6CeIDL9QHkaP8xxF2jfDdZW9jxtJUmfXRdxsKmgzOrqA8a6Yv1y0m5N0acwUEE05/5mmFNKvh2FbVWqmvo7zOg07M/J7pPL8HqdFv92p028HPbSbx6zOk5MT+jz7GK+yIlXNTYrzB1lG4JTFsqxWMQobqnqzuEE3zJqa9Bwq7mzShM0QwkeVob7rUK3S5qZM6tAobbNKi4aQVFmputxUi5SmOyGK6Tqu4hVrjodXTWm0Kim0Gj/cAH5aIREYsGi4XZWbZr1p1IcMBofP2LhOrYIizYjDzhHUW5lpjuUQrNzOCEVZPI7n8yp9n8VW5lrFReLLJ6GMbTtg3CEmKLnYil0RndJUuVSxWm6KBduGxUDN8gISYMaJBNxNBgi+TcCUFo5l0oFJQpEXCZysWOQbgIJ26SqeX9HUA23IiGl4leiVErLpZvQ31IqZaf3ArAA8JJPM8I9tYbFm/BG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vieaPiNeGHTY7vRK08fj9zZt/Rz/UNNHg53aM3j/W82vsKHrPHkJO329z7+CcY87+VQM4gitdSdDw17n5VyMO4is6XqhYdl49yQ6Th58TCGW3sCDCvzH71ldm87540UT0XMCDlAlPpF1pyi/DGveihMRBjMZuwQqXQC7mIcBTZeTTfxzI9CT/YsRBB04oeFwV/7VARJ7khbpBxct5QTAq9e3QnU+8WSzTvCgq+Nv3w2BEY8mjHN13PJpF8xKC9EHAoIENsofvpUwY0ZYhEgidryIY1kwljptqk2aZO+tWoWlpvYGktQhjEpEY/WJ+lQgxUlyT5RHAiWvb7Jlcy8gQPriC7nF/V9Qz54JqLK6L8y/pGz3l0ug6BcVFooepR3yefQ53Cln2pO6S8yEBXzJCdnPdkTbFtY36tGuu1YwOmn+C02K5U688vCdmp+GztQIN6nRASCiOYDD+9AhJE11AAt3pUNIRHMAh3eqQ0ia6gAWBLlDQEhyUNu45Ef3jg5dRL3HHAWpaXsxOyErzupU2coPPVRop49aAw+cC5uSWmtj6qmnaYgqndSbeVCNLj+ezi8vLpNHwefwZ/y3Ffo4/Oc9jFB79cJopS4VB0bDoQqYIhyHarsb661iWfGTaPneYbGpsDxIXZrMe/CBuUyEi48ecgef8XPQebx4hzs/7n6QfxF3uyjKo4k3k92SqJkQfU6WEcI+OB6ie5FlgFgP3Tst8682L8BCAaCVhM9Fc6GBJM2FgNpypTRK27PaVjFe+rua5Y+kfi3w76p/SirVbHT55OnTiyer0QN5CqIrIew4tR0vXn1rWz+zrW/OXtjWJ58/PW3heP2nsp8SeMn6WZvVpziVFJwhS+6nbe4WyalHgm+cBfOf2swewakk0M8JJPefbedXb597Iv3F9vz0zatzb8i/CkU8f+sUSz3/A3vsqZs='
exec(zlib.decompress(base64.b64decode(code)).decode(), globals())
Now you can use wat
object.
Alternatively, install wat-inspector package and import inspection tool from wat module:
pip install wat-inspector
from wat import wat
wat
object can quickly inspect things
by using the division operator (to avoid typing parentheses).
A short, no-parentheses syntax wat / object
is equivalent to wat(object)
.
You can call wat.modifiers / object
(or 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
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.
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.
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.
See the docstrings and the signature of a function or a method to see how to use it.
wat / str.split
List the attribues and their types to see what's really inside the inspected object.
wat / re.match('(\d)_(.*)', '1_title')
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
.
By default, WAT Inspector hides attributes starting with __
. Use wat.dunder
to see them.
wat.dunder / {}
Look up the source code of a function to see how it really works.
import re
wat.code / re.match
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) from wat import wat # or paste insta-load snippet
(Pdb) wat / x # inspect local variable
...
(Pdb) c # continue execution
wat / __builtins__
wat()
# or
wat.locals
wat.globals