Skip to content

igrek51/wat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ™€ 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 your program) 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

Import

Install wat-inspector package and import inspection tool from wat module:

pip install wat-inspector
from wat import wat

Alternatively, use Insta-Load in the section below.

Insta-Load

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 = 'eJzNWumO20YS/j9P0Zj8EGXTiifeA1Ai7zrxxDHgJAtnsoExNghKpGYYU6RAUh5PtALyEPsM+2D7JFtHH9U8JM1sAsSAR1J31dddR1dXV/eyKlcqiZt4kcd1ndYqW63LqnFNJ7ohK+p1umhUXKu6SSL90/SWlq5Kzbf6tj5ZInxzu86KK4P8rLgN1fNs0YTqVVbD3+/XTVYWcR6qi9t1GqqXTVrF8xy+/VhAx8nf3Vzor3rJY39VFsvsanqi4F99DdBTNS/LnH4nmyJJK9FQlEm5qEVDXhZX4ueiTFL9c2i8Z01TZfNNk/KQRbwCjrqp6NeHON/ATxCOfoLI8AvlYfQ4z1GkfTNcV9mHuJEkdXZVxM2mgjajo0sY7x3zl4t2c5IujZkCoinnP9OUQvr1IGyrSs3U13Fep2FnRn6PVJ7f47Totzt1+u2gh3bzmNV5enpKn+cf41VWpKq5TnH+IMsInLJYltUqRmFDVW8W1+iGWVOTnkPFnU2asBlC+Kgy1H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/CkU8e+MUSz3/A8/TbtM='
exec(zlib.decompress(base64.b64decode(code.encode())).decode(), globals())

Now you can use wat object.

Usage & modifiers

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 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() to inspect locals() variables.

Type wat in the interpreter to learn more about this object itself.

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

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) from wat import wat  # or paste insta-load snippet
(Pdb) wat / x  # inspect local variable
...
(Pdb) c  # continue execution

Explore Python built-ins

wat / __builtins__

Look up local variables

wat()
# or
wat.locals

Look up global variables

wat.globals