jasily/lang/with_any.py
def with_objattr(name):
    '''
    wrap `with getattr(self, name)` out of func.

    usage:

    ``` py
    class A:
        def __init__(self):
            self._lock = RLock()

        @with_objattr('_lock') # so easy to make a sync instance method !
        def func():
            pass
    ```
    '''

    def _wrap(func):

        @functools.wraps(func)
        def wrapper(self, *args, **kwargs):
            with getattr(self, name):
                return func(self, *args, **kwargs)

        return wrapper

    return _wrap
def with_objattr(name):
    '''
    wrap `with getattr(self, name)` out of func.

    usage:

    ``` py
    class A:
        def __init__(self):
            self._lock = RLock()

        @with_objattr('_lock') # so easy to make a sync instance method !
        def func():
            pass
    ```
    '''

    def _wrap(func):

        @functools.wraps(func)
        def wrapper(self, *args, **kwargs):
            with getattr(self, name):
                return func(self, *args, **kwargs)

        return wrapper

    return _wrap
def with_objattr ( name ) : def _wrap ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , * * kwargs ) : with getattr ( self , name ) : return func ( self , * args , * * kwargs ) return wrapper return _wrap
wrap `with getattr(self, name)` out of func.

    usage:

    ``` py
    class A:
        def __init__(self):
            self._lock = RLock()

        @with_objattr('_lock') # so easy to make a sync instance method !
        def func():
            pass
    ```
wrap with getattr ( self name ) out of func .