| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 | Metadata-Version: 2.2Name: wraptVersion: 1.17.2Summary: Module for decorators, wrappers and monkey patching.Home-page: https://github.com/GrahamDumpleton/wraptAuthor: Graham DumpletonAuthor-email: Graham.Dumpleton@gmail.comLicense: BSDProject-URL: Bug Tracker, https://github.com/GrahamDumpleton/wrapt/issues/Project-URL: Changelog, https://wrapt.readthedocs.io/en/latest/changes.htmlProject-URL: Documentation, https://wrapt.readthedocs.io/Keywords: wrapper,proxy,decoratorPlatform: anyClassifier: Development Status :: 5 - Production/StableClassifier: License :: OSI Approved :: BSD LicenseClassifier: Programming Language :: Python :: 3Classifier: Programming Language :: Python :: 3.8Classifier: Programming Language :: Python :: 3.9Classifier: Programming Language :: Python :: 3.10Classifier: Programming Language :: Python :: 3.11Classifier: Programming Language :: Python :: 3.12Classifier: Programming Language :: Python :: 3.13Classifier: Programming Language :: Python :: Implementation :: CPythonClassifier: Programming Language :: Python :: Implementation :: PyPyRequires-Python: >=3.8Description-Content-Type: text/x-rstLicense-File: LICENSEwrapt=====|PyPI|The aim of the **wrapt** module is to provide a transparent object proxyfor Python, which can be used as the basis for the construction of functionwrappers and decorator functions.The **wrapt** module focuses very much on correctness. It therefore goesway beyond existing mechanisms such as ``functools.wraps()`` to ensure thatdecorators preserve introspectability, signatures, type checking abilitiesetc. The decorators that can be constructed using this module will work infar more scenarios than typical decorators and provide more predictable andconsistent behaviour.To ensure that the overhead is as minimal as possible, a C extension moduleis used for performance critical components. An automatic fallback to apure Python implementation is also provided where a target system does nothave a compiler to allow the C extension to be compiled.Documentation-------------For further information on the **wrapt** module see:* http://wrapt.readthedocs.org/Quick Start-----------To implement your decorator you need to first define a wrapper function.This will be called each time a decorated function is called. The wrapperfunction needs to take four positional arguments:* ``wrapped`` - The wrapped function which in turns needs to be called by your wrapper function.* ``instance`` - The object to which the wrapped function was bound when it was called.* ``args`` - The list of positional arguments supplied when the decorated function was called.* ``kwargs`` - The dictionary of keyword arguments supplied when the decorated function was called.The wrapper function would do whatever it needs to, but would usually inturn call the wrapped function that is passed in via the ``wrapped``argument.The decorator ``@wrapt.decorator`` then needs to be applied to the wrapperfunction to convert it into a decorator which can in turn be applied toother functions... code-block:: python    import wrapt        @wrapt.decorator    def pass_through(wrapped, instance, args, kwargs):        return wrapped(*args, **kwargs)    @pass_through    def function():        passIf you wish to implement a decorator which accepts arguments, then wrap thedefinition of the decorator in a function closure. Any arguments suppliedto the outer function when the decorator is applied, will be available tothe inner wrapper when the wrapped function is called... code-block:: python    import wrapt    def with_arguments(myarg1, myarg2):        @wrapt.decorator        def wrapper(wrapped, instance, args, kwargs):            return wrapped(*args, **kwargs)        return wrapper    @with_arguments(1, 2)    def function():        passWhen applied to a normal function or static method, the wrapper functionwhen called will be passed ``None`` as the ``instance`` argument.When applied to an instance method, the wrapper function when called willbe passed the instance of the class the method is being called on as the``instance`` argument. This will be the case even when the instance methodwas called explicitly via the class and the instance passed as the firstargument. That is, the instance will never be passed as part of ``args``.When applied to a class method, the wrapper function when called will bepassed the class type as the ``instance`` argument.When applied to a class, the wrapper function when called will be passed``None`` as the ``instance`` argument. The ``wrapped`` argument in thiscase will be the class.The above rules can be summarised with the following example... code-block:: python    import inspect        @wrapt.decorator    def universal(wrapped, instance, args, kwargs):        if instance is None:            if inspect.isclass(wrapped):                # Decorator was applied to a class.                return wrapped(*args, **kwargs)            else:                # Decorator was applied to a function or staticmethod.                return wrapped(*args, **kwargs)        else:            if inspect.isclass(instance):                # Decorator was applied to a classmethod.                return wrapped(*args, **kwargs)            else:                # Decorator was applied to an instancemethod.                return wrapped(*args, **kwargs)Using these checks it is therefore possible to create a universal decoratorthat can be applied in all situations. It is no longer necessary to createdifferent variants of decorators for normal functions and instance methods,or use additional wrappers to convert a function decorator into one thatwill work for instance methods.In all cases, the wrapped function passed to the wrapper function is calledin the same way, with ``args`` and ``kwargs`` being passed. The``instance`` argument doesn't need to be used in calling the wrappedfunction.Repository----------Full source code for the **wrapt** module, including documentation filesand unit tests, can be obtained from github.* https://github.com/GrahamDumpleton/wrapt.. |PyPI| image:: https://img.shields.io/pypi/v/wrapt.svg?logo=python&cacheSeconds=3600   :target: https://pypi.python.org/pypi/wrapt
 |