Skip to content

Commit 0a190a6

Browse files
author
James William Pye
committed
Fix method decorator.
1 parent 74b8853 commit 0a190a6

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

postgresql/documentation/changes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
-----
1111
1212
* Fix encoding normalization.
13+
* Fix "method" decorator to return callable when val is None.
1314
1415
0.8.0 released on 2009-04-03
1516
----------------------------

postgresql/python/decorlib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ class method(object):
4040
def __init__(self, callable):
4141
self.callable = callable
4242
def __get__(self, val, typ):
43-
return types.MethodType(self.callable, val or typ)
43+
if val is None:
44+
return self.callable
45+
return types.MethodType(self.callable, val)

postgresql/test/test_python.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def testComposition(self):
3030
self.failUnlessEqual("100", simple("100"))
3131
timesfour_fourtimes = compose((methodcaller('__mul__', 4),)*4)
3232
self.failUnlessEqual(4*(4*4*4*4), timesfour_fourtimes(4))
33+
nothing = compose(())
34+
self.failUnlessEqual(nothing("100"), "100")
35+
self.failUnlessEqual(nothing(100), 100)
36+
self.failUnlessEqual(nothing(None), None)
3337

3438
def testRSetAttr(self):
3539
class anob(object):

0 commit comments

Comments
 (0)