Package: aspectlib
aspectlibis an aspect-oriented programming, monkey-patch and decorators library. It is useful when changing
behavior in existing code is desired. It includes tools for debugging and testing: simple mock/record and a complete
capture/replay framework.Free software: BSD 2-Clause LicenseInstallationpip install aspectlibYou can also install the in-development version with:pip install https://github.com/ionelmc/python-aspectlib/archive/main.zipDocumentationDocs are hosted at readthedocs.org:python-aspectlib docs.Implementation statusWeaving functions, methods, instances and classes is completed.Pending:“Concerns”(seedocs/todo.rst)Ifaspectlib.weavedoesn’t work for your scenario please report a bug!RequirementsOS:AnyRuntime:Python 2.6, 2.7, 3.3, 3.4 or PyPyPython 3.2, 3.1 and 3.0 areNOTsupported (some objects are too crippled).Similar projectsfunction_trace- extremely simpleChangelog2.0.0 (2022-10-20)Drop support for legacy Pythons (2.7, 3.6 or older).Remove Travis/Appveyor CI and switch to GitHub Actions.Added support for Tornado 6 (in the test suite).1.5.2 (2020-11-15)Fixed broken import on Python 3.9.
Contributed by Felix Yan in#19.1.5.1 (2020-06-11)Remove some debug leftover prints fromv1.5.0.1.5.0 (2020-04-05)Fixedweaveto stop reading attributes that don’t match the method selector.
Contributed by Jonas Maurus in#14.Added support for Python 3.7 and 3.8 (async deffunctions and generators).1.4.2 (2016-05-10)Fix forgotten debug prints.1.4.1 (2016-05-06)Fixed weaving of objects that don’t live on root-level modules.1.4.0 (2016-04-09)Corrected weaving of methods, the weaved function should be unbound.Rolling back only applies undos once.Added a convenienceweavefixture for pytest.1.3.3 (2015-10-02)Fixed typo inABSOLUTELLY_ALL_METHODSname (nowABSOLUTELY_ALL_METHODS). Old name is still there for
backwards compatibility.1.3.2 (2015-09-22)Fixed another tricky bug in the generator advising wrappers - result was not returned if onlyProceedwas yielded.1.3.1 (2015-09-12)Corrected result handling when using Aspects on generators.1.3.0 (2015-06-06)Addedmessagesproperty toaspectlib.test.LogCapture. Changecallto have level name instead of number.Fixed a bogus warning fromaspectlib.patch_module`when patching methods on old style classes.1.2.2 (2014-11-25)Added support for weakrefs in the__logged__wrapper fromaspectlib.debug.logdecorator.1.2.1 (2014-10-15)Don’t raise exceptions fromReplay.__exit__if there would be an error (makes original cause hard to debug).1.2.0 (2014-06-24)Fixed weaving methods that were defined in some baseclass (and not on the target class).Fixed wrong qualname beeing used in the Story/Replay recording. Now used the alias given to the weaver instead of
whatever is the realname on the current platform.1.1.1 (2014-06-14)UseASPECTLIB_DEBUGfor every logger inaspectlib.1.1.0 (2014-06-13)Added abindoption toaspectlib.Aspectso you can access the cutpoint from the advisor.Replaced automatic importing inaspectlib.test.Replaywith extraction of context variables (locals and globals
from the callingaspectlib.test.Story). Works better than the previous inference of module from AST of the
result.All the methods on the replay are now properties:aspectlib.test.Story.diff,aspectlib.test.Story.unexpectedandaspectlib.test.Story.missing.Addedaspectlib.test.Story.actualandaspectlib.test.Story.expected.Added anASPECTLIB_DEBUGenvironment variable option to switch on debug logging inaspectlib’s internals.1.0.0 (2014-05-03)Reworked the internalsaspectlib.test.Storyto keep call ordering, to allow dependencies and improved the
serialization (used in the diffs and the missing/unexpected lists).0.9.0 (2014-04-16)Changedaspectlib.test.record:Renamedhistoryoption tocalls.Renamedcalloption toiscalled.Addedcallbackoption.Addedextendedoption.Changedaspectlib.weave:Allow weaving everything in a module.Allow weaving instances of new-style classes.Addedaspectlib.test.Storyclass for capture-replay and stub/mock testing.0.8.1 (2014-04-01)Use simpler import for the py3support.0.8.0 (2014-03-31)Changeaspectlib.debug.logto useaspectlib.Aspectand work as expected with coroutines or generators.Fixedaspectlib.debug.logto work on Python 3.4.Remove the undocumentedaspectlib.Yieldadvice. It was only usable when decorating generators.0.7.0 (2014-03-28)Add support for decorating generators and coroutines inaspectlib.Aspect.Made aspectlib raise better exceptions.0.6.1 (2014-03-22)Fix checks insideaspectlib.debug.logthat would inadvertently call__bool__/__nonzero.0.6.0 (2014-03-17)Don’t include __getattribute__ in ALL_METHODS - it’s too dangerous dangerous dangerous dangerous dangerous dangerous
… ;)Do a more reliable check for old-style classes in debug.logWhen weaving a class don’t weave attributes that are callable but are not actually routines (functions, methods etc)0.5.0 (2014-03-16)Changedaspectlib.debug.log:Renamedargumentstocall_args.Renamedarguments_reprtocall_args_repr.Addedcalloption.Fixed issue with logging from old-style methods (object name was a generic “instance”).Fixed issues with weaving some types of builtin methods.Allow to apply multiple aspects at the same time.Validate string targets before weaving.aspectlib.weave('mod.invalidname', aspect)now gives a clear error
(invalid nameis not a valid identifier)Various documentation improvements and examples.0.4.1 (2014-03-08)Remove junk from 0.4.0’s source distribution.0.4.0 (2014-03-08)Changedaspectlib.weave:Replacedonly_methods,skip_methods,skip_magicmethodsoptions withmethods.Renamedon_initoption tolazy.Addedaliasesoption.Replacedskip_subclassesoption withsubclasses.Fixed weaving methods from a string target.0.3.1 (2014-03-05)???0.3.0 (2014-03-05)First public release.