[cfe-commits] r162190 - /cfe/trunk/bindings/python/clang/cindex.py

Sean Silva silvas at purdue.edu
Sun Aug 19 17:45:53 PDT 2012


+    def __init__(self, wrapped):
+        self.wrapped = wrapped
+        try:
+            self.__doc__ = wrapped.__doc__
+        except:
+            pass

Please use functools.wraps() here.

-- Sean Silva

On Sun, Aug 19, 2012 at 5:17 PM, Gregory Szorc <gregory.szorc at gmail.com> wrote:
> Author: gps
> Date: Sun Aug 19 16:17:46 2012
> New Revision: 162190
>
> URL: http://llvm.org/viewvc/llvm-project?rev=162190&view=rev
> Log:
> [clang.py] Add CachedProperty decorator
>
> It isn't used anywhere yet.
>
> Modified:
>     cfe/trunk/bindings/python/clang/cindex.py
>
> Modified: cfe/trunk/bindings/python/clang/cindex.py
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=162190&r1=162189&r2=162190&view=diff
> ==============================================================================
> --- cfe/trunk/bindings/python/clang/cindex.py (original)
> +++ cfe/trunk/bindings/python/clang/cindex.py Sun Aug 19 16:17:46 2012
> @@ -133,6 +133,31 @@
>
>  ### Structures and Utility Classes ###
>
> +class CachedProperty(object):
> +    """Decorator that lazy-loads the value of a property.
> +
> +    The first time the property is accessed, the original property function is
> +    executed. The value it returns is set as the new value of that instance's
> +    property, replacing the original method.
> +    """
> +
> +    def __init__(self, wrapped):
> +        self.wrapped = wrapped
> +        try:
> +            self.__doc__ = wrapped.__doc__
> +        except:
> +            pass
> +
> +    def __get__(self, instance, instance_type=None):
> +        if instance is None:
> +            return self
> +
> +        value = self.wrapped(instance)
> +        setattr(instance, self.wrapped.__name__, value)
> +
> +        return value
> +
> +
>  class _CXString(Structure):
>      """Helper for transforming CXString results."""
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list