wrapt targets instrumentation of Python code such as APM agents, tracers, profilers, and debuggers without requiring user modifications. The project’s decorator API grew from needs for reliable monkey patching building blocks. Deferred monkey patching has existed since the beginning, allowing patches to be registered for modules that have not yet been imported and applied when the module is later imported. Documentation for this mechanism was added ahead of the 2.2.0 release, which also introduced an ergonomic module-name “?” modifier to close a composition gap with decorator syntax. With Python 3.15 and PEP 810 introducing explicit lazy import syntax, libraries that force-import targets at agent startup conflict with user intent and harm cold-start performance.
"The reason I want to call out the audience up front is that wrapt was created for this kind of work, and the original purpose is sometimes obscured by how widely the project has been adopted for its decorator API. The decorator side of wrapt (which the recent posts on stateful decorators and per-instance lru_cache have covered) grew out of needing reliable building blocks for monkey patching, not the other way around."
"The mechanism for deferred monkey patching, registering a patch against a module that has not been imported yet, with the patch only applied when the module is later imported, has been part of wrapt from day one. The monkey patching documentation page finally landed in the lead-up to the 2.2.0 release, which also added a small ergonomic piece. A new ? modifier on module names closes the last awkward gap in how the deferred form composes with the convenient decorator syntax."
"With Python 3.15 about to ship PEP 810 explicit lazy import syntax, the timing matters. Any instrumentation library that force-imports its target modules at agent startup is now actively undoing user-level lazy imports. That has always been a little impolite for cold-start performance. With 3.15 it becomes a direct conflict with how users want to write their code."
"The smallest useful piece of wrapt's monkey patching API is wrap_function_wrapper. You give it a module, the dotted name of an attribute on that module, and a wrappe"
Read at Grahamdumpleton
Unable to calculate read time
Collection
[
|
...
]