"The actual reason wrapt was created was to be able to perform monkey patching of Python code. One key aspect of being able to monkey patch Python code is to be able to have the ability to wrap target objects in Python with a wrapper which acts as a transparent object proxy for the original object. By extending the object proxy type, one can then intercept access to the target object to perform specific actions."
"When I saw this PEP it made me realise that a new feature I added into wrapt for upcoming 2.0.0 release can be used to implement a lazy import with little effort. For those who only know of wrapt as being a package for implementing Python decorators, it should be known that the ability to implement decorators using the approach it does, was merely one outcome of the true reason for wrapt existing."
PEP 810 adds explicit syntax for implementing lazy imports for modules in Python. Lazily importing modules is an established pattern implemented by external packages but those packages lacked explicit language syntax. A recent wrapt feature can be used to implement lazy imports with minimal effort. Wrapt was created to support monkey patching and provides an ObjectProxy type that acts as a transparent proxy for target objects. Extending the object proxy enables interception of access to the target object to perform actions. Wrapping a module with ObjectProxy permits using the proxy just like the original module, deferring import or attribute access.
Read at Grahamdumpleton
Unable to calculate read time
Collection
[
|
...
]