Skip to main content

tools to assist with debug

Project description

pusher_debug

pusher_debug.tracing

Tools to aid in adding print statements to trace program flow:

  • ObjWatch from the objwatch library
  • DetailWrapper, a "wrapper" to use with Objwatch that provides more details on function calls and returns, and can be subclassed easily to provide distinct id strings for different instances of selected classes.
  • fn_name, fn_entry, and fn_exit, to provide manual logging of details of function you enter (caller, parameters, return value, annotations)

pusher_debug.monkeypatching

Tools to aid in monkeypatching. Two decorators:

@add_new_class(ExistingClass)
class MyClass: ...

will (in the module where ExistingClass is defined)

  1. Create orig_ExistingClass, as a backup of ExistingClass
  2. Create new_ExistingClass, as a backup of MyClass
  3. Make ExistingClass be new_ExistingClass (fixing __name__ and __qualname__ between new_ExistingClass and orig_ExistingClass as well)
    Then restore_class(ExistingClass) will restore the original, and restore_new_class(ExistingClass) will put back the new version again.
@add_to_class(ExistingClass)
def fn():...

will (in ExistingClass) add a method fn. If fn already exists, the the original is backed up as orig_fn. new_fn is created and names are fixed as for @add_new_class.

@add_to_class can be combined with one of @classmethod, @staticmethod, or @property (and if property, then fn in the local namespace will be the property, so you can then do

@add_to_class(ExistingClass)
@fn@setter
def fn():...
  1. Create ExistingClass.orig_fn, as a backup of ExistingClass.fn
  2. Create ExistingClass.new_fn, as a backup of fn
  3. Make ExistingClass be new_ExistingClass (fixing __name__ and __qualname__ between new_ExistingClass and orig_ExistingClass as well)
  4. Specifically deals with special issues for @classmethod, @staticmethod, and @property
  5. Specifically deals with condition that ExistingClass.fn was actually defined in a parent class of ExistingClass, so we don't want to change the parent class (copy fn to ExistingClass [not just ExistingClass.fn = ParentClass.fn)
  6. Specifically deals with condition that ExistingClass.fn is a builtin, and can't be copied in the same way (or modified at all, even __name__)

You should know that monkeypatching will wreack havoc with mypy, since it does stuff you shouldn't do. (It's for debugging !)

For examples, use help(...), and/or download the source package and look at the tests. Seeing all the # test: ignore[] stuff in the test program gives you an idea of how much mypy hates this.

The library can be built with hatchling build, tested with tests/test_tools.py -v, and should pass mypy (including having annotations for objwatch).

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

pusher_debug-1.2.0.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pusher_debug-1.2.0-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file pusher_debug-1.2.0.tar.gz.

File metadata

  • Download URL: pusher_debug-1.2.0.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pusher_debug-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e06f4b1647d297ff453103e49f3e4427d1e920e66822878aad3cf7bd55cc57ae
MD5 8aa7e778207fbbadcab77cc190d6e3a8
BLAKE2b-256 c6e75479b7dbf0429abe79da0d2a9cf4cee76f74633a0c23101a3143a262b2a3

See more details on using hashes here.

File details

Details for the file pusher_debug-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pusher_debug-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pusher_debug-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e68d3cba3208ad8e34173211bb45d18a29fe84be0c431f45cace7fcfcc09042e
MD5 e8a633ec57713982fcaf1bc6793c6a66
BLAKE2b-256 66edda63feba108a21efebaf3b30908b5e8e47a781f0342d054b7425360ee7f2

See more details on using hashes here.

Supported by

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