]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
replaced metaclass/__new__ insanity with a __call__()
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Aug 2007 01:31:28 +0000 (01:31 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Aug 2007 01:31:28 +0000 (01:31 +0000)
lib/sqlalchemy/orm/sessionmaker.py

index adf80f9a7bb69e403bec084cb305debed12bf9fb..13e28fd1aa1d9151b8f930f822a0315b558007a3 100644 (file)
@@ -66,20 +66,8 @@ def sessionmaker(autoflush, transactional, bind=None, scope=None, enhance_classe
             
         default_scope=scope
         
-        class ScopedProps(type):
-            pass
-        def makeprop(name):
-            def set(self, attr):
-                setattr(registry(), name, attr)
-            def get(self):
-                return getattr(registry(), name)
-            return property(get, set)
-        for prop in ('bind', 'dirty', 'identity_map'):
-            setattr(ScopedProps, prop, makeprop(prop))
-            
         class ScopedSess(Sess):
-            __metaclass__ = ScopedProps
-            def __new__(cls, **kwargs):
+            def __call__(self, **kwargs):
                 if len(kwargs):
                     scope = kwargs.pop('scope', default_scope)
                     if scope is not None:
@@ -93,14 +81,24 @@ def sessionmaker(autoflush, transactional, bind=None, scope=None, enhance_classe
                         return Sess(**kwargs)
                 else:
                     return registry()
+                    
         def instrument(name):
             def do(cls, *args, **kwargs):
                 return getattr(registry(), name)(*args, **kwargs)
-            return classmethod(do)
+            return do
         for meth in ('get', 'close', 'save', 'commit', 'update', 'flush', 'query', 'delete'):
             setattr(ScopedSess, meth, instrument(meth))
             
-        return ScopedSess
+        def makeprop(name):
+            def set(self, attr):
+                setattr(registry(), name, attr)
+            def get(self):
+                return getattr(registry(), name)
+            return property(get, set)
+        for prop in ('bind', 'dirty', 'identity_map'):
+            setattr(ScopedSess, prop, makeprop(prop))
+            
+        return ScopedSess()
     elif scope is not None:
         raise exceptions.ArgumentError("Unknown scope '%s'" % scope)
     else: