$ show igrek51/wat
WAT is a zero-dependency Python library for deep runtime inspection of objects. It provides a single `wat` object that can be used via `wat / obj`, `wat(obj)`, or `obj | wat` to display the object's type, value, attributes, methods, signatures, docstrings, source code, and more. The library supports a rich set of modifiers (short, long, dunder, code, caller, public, all) that can be chained fluently. It also offers `wat.locals` and `wat.globals` to inspect variable scopes. A notable feature is the ability to load the entire inspector without installation via a base64-compressed snippet or even a single Unicode glyph, making it extremely portable for debugging in any Python environment. The codebase is a single well-structured module with comprehensive test coverage, demonstrating solid Python engineering practices including operator overloading, AST manipulation for minification, and careful handling of edge cases in object introspection.
The LLM identified 2 files worth highlighting for reuse:
The core inspection engine. The `inspect_format` function takes any Python object and returns a richly formatted string with type, value, attributes, methods, signatures, docstrings, and source code. The `Wat` class provides a fluent API via `__truediv__`, `__getattr__` for modifiers, and `__call__` for direct invocation. It handles all built-in types, callables, classes, modules, and custom objects, with configurable output (short/long, color, dunder, etc.). This component is self-contained (stdlib only) and could be extracted as a standalone inspection utility.
A utility that minifies the inspection source code by stripping type hints via AST transformation and removing comments and whitespace. It uses `ast.NodeTransformer` to recursively remove annotations from function arguments, return types, and variable assignments. This component demonstrates non-obvious skill in Python AST manipulation and is reusable for any project needing to strip type hints or minify Python code programmatically.