summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES8
-rw-r--r--lib/sqlalchemy/engine/base.py4
-rw-r--r--lib/sqlalchemy/util.py4
-rw-r--r--test/base/test_utils.py34
4 files changed, 45 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index e8bea81ce..3347fe397 100644
--- 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
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index a02cb81a0..81ef6a329 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -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
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py
index 7ac0d9ffd..bcd341750 100644
--- a/lib/sqlalchemy/util.py
+++ b/lib/sqlalchemy/util.py
@@ -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
diff --git a/test/base/test_utils.py b/test/base/test_utils.py
index f9888ef0c..68ccc6ba2 100644
--- a/test/base/test_utils.py
+++ b/test/base/test_utils.py
@@ -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):