Skip to main content

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 fn (or new_fn) be ExistingClass.fn and ExistingClass.new_fn (fixing __name__ and __qualname__ between versions of ExistingClass.fn
  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).

Metadata

Release files for pusher-debug 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pusher-debug 1.2.1
File Size Uploaded
pusher_debug-1.2.1.tar.gz 36.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pusher-debug 1.2.1
File Interpreter ABI Platform
pusher_debug-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 67.7 kB

Release files / pusher_debug-1.2.1.tar.gz

Download URL pusher_debug-1.2.1.tar.gz
Size 36.1 kB
Tags Source
SHA-256 checksum
How to use checksums
563acb24c764a4aafca56ab6590764eff9113f192938d3b40171617b2255554c
BLAKE2b-256 checksum
How to use checksums
c83065060c111b9233bcab4f2933659dc8d95f714f1d3c354bd0fb4c6b914e03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / pusher_debug-1.2.1-py3-none-any.whl

Download URL pusher_debug-1.2.1-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
017fed09bee422514df490f9a8acf324f53a05a5b18b296ec4cc9a89e01bd19b
BLAKE2b-256 checksum
How to use checksums
8b3bd0eb5c6d26263282658b47773fae449d154a8e5310fde1cd78e23f8f7353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page