Skip to main content

One decorator for lazy debugging. Inserts print statements directly into your AST.

Project description

constable allows you to monitor the state of specified variables at each assignment operation, providing a step-by-step view of variable changes!

View the Github repository and the official docs.

How does it work?

The constable.trace decorator uses Python’s Abstract Syntax Tree (AST) in much the same way we add print`(s) to debug states. During runtime, it prepares and inserts `print statements into the function’s AST after every assignment operation (ast.Assign, ast.AugAssign and ast.AnnAssign), and then executes the modified code in a separate namespace with exec.

$ pip install constable

Tested for python 3.8 and above.

Usage :

Monitoring functions

import constable

@constable.trace(['a', 'b'])
def example(a, b):
    a = a + b
    c = a
    a = "Experimenting with the AST"
    b = c + b
    a = c + b
    return a

example(5, 6)

Output :

constable.trace: example:19 -
    a = a + b
    a = 11
    type(a) = <class 'int'>

constable.trace: example:21 -
    a = "Experimenting with the AST"
    a = Experimenting with the AST
    type(a) = <class 'str'>

constable.trace: example:22 -
    b = c + b
    b = 17
    type(b) = <class 'int'>

constable.trace: example:23 -
    a = c + b
    a = 28
    type(a) = <class 'int'>

constable.trace: example -
    args: (5, 6)
    kwargs: {}
    returned: 28
    execution time: 0.00029278 seconds

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

constable-0.3.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

constable-0.3.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file constable-0.3.0.tar.gz.

File metadata

  • Download URL: constable-0.3.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for constable-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c197e7ebadf1aed6a5538be9fa847fdf0e0a38357cf093a811091dac9c94d4cb
MD5 fd94386458ae8c4349bde11f5c47c04b
BLAKE2b-256 a1603ea2190bebd296243d420a57d6afca4fe2706f5bac423956fbbd2029f7ba

See more details on using hashes here.

Provenance

File details

Details for the file constable-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: constable-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for constable-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 308c2848c1c54eac4f257adbbace1eab445397dd24e8d3414ebe23198c4923c8
MD5 66bc8443b3e7e44134b17ad697ef9ff4
BLAKE2b-256 c7c3a0f100ed446411ab3f0c47d2cb26f56d9b928b220d26b102bf61b61d80f4

See more details on using hashes here.

Provenance

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