Skip to main content

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/1u28gR/z9PsUj/IJnoVDvpB+A7pfUlanqA71L4fA0CxyAocWXzQpECScV2BQH3EH2Ge7A+SedjP/khyW4KFA1wMrm785vZmdmZ2eXeoiqXIk2aZJ4ndS1rkS1XZdXYpieqISvqlZw3+rU0HZXUT/V9/WSBeM39KiuuNdRpcT8Sb7J5MxJnWQ2/71ZNVhZJPhIX9ys5Et81skpmOTz9VEDHkz9b5vQrvmPer8tikV2fPBHwr74B6BMxK8uc3tN1kcrKaSjKtJzXTkNeFtfO67xMpXod4nfaNFU2WzeSWRbJEijqpqK3z0m+hleYHL3ClOEN58PoSZ7jlHZJuKqyz0njDqmz6yJp1hW0aR1dAr8rpi/n7eZULrRd4kVZLZMmpKHl7OcRPTwbWWVN/pLktRw5srgtrC63BfXlvqPC3HeYoX6NTtQItM/Es1bIvOl3pPnyH1FWCDLSvPnPiBnjjxlArPFHtUQ8y3WzWjeTS1YPKCQmm0yUKvgtBF3w8Equ9Ah8tB3ZwukTkwlCUS9y83ti6MpW8bzMyyo0HNX0rUzjZLWSRRougs2PFx/OpvG359+9/etF/O3ZT9MtO87mfPrj9GIrNgZlG7A4ElT6IEBA2AF3IAjO06K4/duN1cFWjVDYyAwd36gcX0L6Qf25ZtrJnBaPNwVs0VxWSSWLpp4EIxGMfy6zIoyvZRNzM42sHZ7GporsQarUNEYW1aBFAVi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RD0AMc9WmRCW0CpP7mPuC/lPy4YLn7K77Vf680a1IdzUjh8lwwDGBSP+IBANY+L0+ozlXXFY4PWcvKWvQTX7NQN5bSv3FvI2BvIJO9BuzaqxpmzxJtpaEkp2RWKXZssKym3YFt7C7GoRQ6JRI0ax/dFDOZIXP9qG7+UFBAMW8zygFYba0J0vzbYOsuuLVWDeR6LJmtzlyueWuDbNFTVL3aFr3/fadWWLkIdvbDlT2LuEOO42sKzT7LMJvSoeeCg6YnCfQ5yk6eMI8/omWzSPo63+A9qyeiTPxxLmjxRUXQ4zxHQLshsDCITXsfCyNAxHd9kEVOziDeA62PrLwsQGP3hcKpIrP+JTOiPYyUQEWFcGB8LR2J1oXBcfiqdG70TEWvlQPBq7E43r3kPx1OidiJAQDoXDoTuxMFUNYHF8vKQhOzEweO7BwCE7MSjY7wGhMXs8Cwvf4L9YA/VIztXww5kyYYvr21YFPcgWNDPMcldFmGS1FOayJF3bGsriulDQ3zLaVTkjK6JKjuv1LKyCj3fHs4+XH9Pn4dfwE/1piQEE/uOinZB6k7gsPnPHZGMEChaYkoMT4fyfR9SOmQea0Re4dUuJvKzHAJNVZcF5/f3pRfz63dm7c5Ihgp3RraxCe6Pb8HSzYeeww4xy59tzGZwn1+9R6qNPhddR9Q22+brCD2HUqGoprzbG3B1jJK6S4lqGL7pfsoi0X3YDQizpd7yIZ8n805PDAfSnH0XN66utHnWc1SlVU5kzpaOXrtP/XyhGBYFHamZ/lcek/UfCGxqy9Q+CUUM6j6v/gcLuyvE2fOjeKdLXodWAS6S88nsHbym6FxS5gLYbvd7ric7tajtUT23ojuIDryeSKqAUPnr58vJoGTxxMVXzsWk+n77RQ79+edwa7fQeu710bmPJXrTJ3P5jt5+lt5Qv25TegGNvwNlPU0v4uzah033sdqtrcJby96br9YdTZxJ/cGZ3+kG1v/j65R+Xwb8ByQAMSg=='
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. 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)
  • .dunder to display dunder attributes
  • .code to reveal the source code of a function, method, or class
  • .long to show non-abbreviated values and documentation
  • .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 local variables.
Call wat.globals to inspect global 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 further confusion.

Look up methods

By listing out methods with their signatures and docstrings, you can easily grasp how to use the unknown object.

wat / ['foo']


Use wat.long if you want to see full doscstrings.

Discover function's signature

See the docstrings and the signature of a function to learn 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

Another use case is to explore modules. You can list the functions, classes and 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.

wat.code / wat.__call__

Prettify unreadable collections

Nested dictionaries and lists get nicely formatted, indented output:

Debug with breakpoint

You can use Python's breakpoint() keyword to launch an interactive debugger in your program. Attach to the interpreter and inspect things on the spot.

(Pdb) import wat  # or paste Insta-Load snippet
(Pdb) wat / foo  # inspect local variables
...
(Pdb) c  # continue execution

Look up local variables

Use wat.locals or wat.globals to look up the local and global variables respectively.

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
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(str | None)
# value: str | None
# type: types.UnionType

Explore Python built-ins:

wat / __builtins__
wat / ...
wat / _

Inspect WAT itself

wat.dunder / wat
wat.code / wat.__truediv__

Environment variables

  • WAT_COLOR="false" to disable colorful output in the console.
  • WAT_COLOR="true" to enforce colorful outputs even in non-tty environment.

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wat_inspector-0.3.3.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

wat_inspector-0.3.3-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file wat_inspector-0.3.3.tar.gz.

File metadata

  • Download URL: wat_inspector-0.3.3.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for wat_inspector-0.3.3.tar.gz
Algorithm Hash digest
SHA256 056f4c308cd03247a0836fd3b2c53148abcb902c939ffdecd98bba32fe336b56
MD5 3dfb56a1e69163e8cc8b6a458adb5be3
BLAKE2b-256 59aba18b45e208bf1951f1e69e75bf4ba3e2b0d02cbc3bb9932e53e86be27a5d

See more details on using hashes here.

File details

Details for the file wat_inspector-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for wat_inspector-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 179a6d8f3438f039a219898419b64f4a68afc60cb027a1d70702a286f6308e68
MD5 1660bbda82ec9c97d5c7383efb8788be
BLAKE2b-256 8b92e47c0b9cb8105076469a4bce6a986c86ce9ff3e49365328c1c1ab897041a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page