Commits

Christian Tismer committed 1fcbd9d

much shorter and more general replacer for globals

Comments (0)

Files changed (1)

tool/tiff_reader/tiffany/monkeypil.py

 class TiffanyMeta(type):
     def __new__(_mcs, _name, _bases, _dict):
         meth_globals = inject_into_module.__dict__
-        stmethodtype = type(staticmethod(lambda:None))
         
         def func_with_new_globals(func, globals):
             """Make a copy of a function with new globals."""
                 f.func_dict = {}
                 f.func_dict.update(func.func_dict)
             return f
-
+        
+        ng = func_with_new_globals
         for name, func in _dict.items():
-            if isinstance(func, (types.FunctionType, stmethodtype)):
-                replacing_method = None
-                if isinstance(func, stmethodtype):
-                    func = func.__func__
-                    replacing_method = staticmethod
-                func = func_with_new_globals(func, meth_globals)
-                if replacing_method:
-                    func = replacing_method(func)
-                _dict[name] = func
+            if isinstance(func, types.FunctionType):
+                _dict[name] = ng(func, meth_globals)
+            elif isinstance(func, (staticmethod, classmethod)):
+                _dict[name] = type(func)(ng(func.__func__, meth_globals))
+            elif isinstance(func, property):
+                _dict[name] = property(ng(func.fget, meth_globals))
         return type.__new__(_mcs, _name, _bases, _dict)
 
 Image.core = TiffanyCore()