A lightweight framework that lets you intercept and modify local variables
at any execution point of a target function, using sys.settrace.
import random
from pytrace_inject import At, inject, start_trace, end_trace
@inject(At(random.randrange).atcall())
def modify(start, end):
start, end = 42, 43
return {'start': start, 'end': end}
start_trace()
print(random.randrange(100, 999)) # Output: 42
end_trace()- At — Where to inject (call time / return time / specific line / custom condition).
- Tracer — The active injection, can be
.remove()'d at any time. - Callback — Your function that receives current local variables
and returns a
dictof replacements (orNone).
MIT — see LICENSE file.