]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed @memoized_property and @memoized_instancemethod
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 19 Jun 2010 18:08:20 +0000 (14:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 19 Jun 2010 18:08:20 +0000 (14:08 -0400)
decorators so that Sphinx documentation picks up
these attributes and methods, such as
ResultProxy.inserted_primary_key. [ticket:1830]

CHANGES
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/util.py
test/base/test_utils.py

diff --git a/CHANGES b/CHANGES
index e8bea81ce8fcd81b73a981fcad83e9dea4d230e3..3347fe397387e117e43e8bb3bcf224a118db1731 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -105,7 +105,13 @@ CHANGES
      
 - documentation
   - Added documentation for the Inspector. [ticket:1820]
-  
+
+  - Fixed @memoized_property and @memoized_instancemethod
+    decorators so that Sphinx documentation picks up 
+    these attributes and methods, such as 
+    ResultProxy.inserted_primary_key. [ticket:1830]
+    
+    
 0.6.1
 =====
 - orm
index a02cb81a07d36912bec6558b99f5743bf43617b3..81ef6a32955fa79b7e88441e1ac215d92fb447aa 100644 (file)
@@ -2212,7 +2212,7 @@ class ResultProxy(object):
         consistent across backends.
         
         Usage of this method is normally unnecessary; the
-        inserted_primary_key method provides a
+        :attr:`~ResultProxy.inserted_primary_key` attribute provides a
         tuple of primary key values for a newly inserted row,
         regardless of database backend.
         
@@ -2299,7 +2299,7 @@ class ResultProxy(object):
 
     @util.deprecated("Use inserted_primary_key")
     def last_inserted_ids(self):
-        """deprecated.  use inserted_primary_key."""
+        """deprecated.  use :attr:`~ResultProxy.inserted_primary_key`."""
         
         return self.inserted_primary_key
         
index 7ac0d9ffdbdf6217ee4e96d88844884771399c8b..bcd341750b0438c546b0f75bb16d12a13e82f316 100644 (file)
@@ -1422,7 +1422,7 @@ class memoized_property(object):
 
     def __get__(self, obj, cls):
         if obj is None:
-            return None
+            return self
         obj.__dict__[self.__name__] = result = self.fget(obj)
         return result
 
@@ -1442,7 +1442,7 @@ class memoized_instancemethod(object):
 
     def __get__(self, obj, cls):
         if obj is None:
-            return None
+            return self
         def oneshot(*args, **kw):
             result = self.fget(obj, *args, **kw)
             memo = lambda *a, **kw: result
index f9888ef0c5c89529d8a68a3df6357749676975ec..68ccc6ba2a3e1bea31c37d1f6d5d70df64f8c4fe 100644 (file)
@@ -83,6 +83,40 @@ class FrozenDictTest(TestBase):
         for loads, dumps in picklers():
             print loads(dumps(d))
         
+
+class MemoizedAttrTest(TestBase):
+    def test_memoized_property(self):
+        val = [20]
+        class Foo(object):
+            @util.memoized_property
+            def bar(self):
+                v = val[0]
+                val[0] += 1
+                return v
+                
+        ne_(Foo.bar, None)
+        f1 = Foo()
+        assert 'bar' not in f1.__dict__
+        eq_(f1.bar, 20)
+        eq_(f1.bar, 20)
+        eq_(val[0], 21)
+        eq_(f1.__dict__['bar'] , 20)
+
+    def test_memoized_instancemethod(self):
+        val = [20]
+        class Foo(object):
+            @util.memoized_instancemethod
+            def bar(self):
+                v = val[0]
+                val[0] += 1
+                return v
+
+        ne_(Foo.bar, None)
+        f1 = Foo()
+        assert 'bar' not in f1.__dict__
+        eq_(f1.bar(), 20)
+        eq_(f1.bar(), 20)
+        eq_(val[0], 21)
         
 class ColumnCollectionTest(TestBase):
     def test_in(self):