summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-03-08 06:14:50 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-03-08 06:14:50 (GMT)
commitc8b6d1bd8c9dcd7fd69282ab65dded5c9a89af77 (patch)
tree9d41e1845e634f489eb3682d46378a0fd3d22e68 /Lib
parentff564d3391ef70e453a49d64b68a2f902c40a5b2 (diff)
downloadcpython-c8b6d1bd8c9dcd7fd69282ab65dded5c9a89af77.zip
cpython-c8b6d1bd8c9dcd7fd69282ab65dded5c9a89af77.tar.gz
cpython-c8b6d1bd8c9dcd7fd69282ab65dded5c9a89af77.tar.bz2
Make functional.partial() more closely match the spec by emulating
some useful features of regular functions: * Made weak referencable. * Allow attribute access so a user can set __name__, __doc__, etc.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_functional.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_functional.py b/Lib/test/test_functional.py
index db3a289..8f19d6b 100644
--- a/Lib/test/test_functional.py
+++ b/Lib/test/test_functional.py
@@ -1,6 +1,7 @@
import functional
import unittest
from test import test_support
+from weakref import proxy
@staticmethod
def PythonPartial(func, *args, **keywords):
@@ -116,6 +117,22 @@ class TestPartial(unittest.TestCase):
self.assertRaises(ZeroDivisionError, self.thetype(f), 1, 0)
self.assertRaises(ZeroDivisionError, self.thetype(f, y=0), 1)
+ def test_attributes(self):
+ p = self.thetype(hex)
+ try:
+ del p.__dict__
+ except TypeError:
+ pass
+ else:
+ self.fail('partial object allowed __dict__ to be deleted')
+
+ def test_weakref(self):
+ f = self.thetype(int, base=16)
+ p = proxy(f)
+ self.assertEqual(f.func, p.func)
+ f = None
+ self.assertRaises(ReferenceError, getattr, p, 'func')
+
class PartialSubclass(functional.partial):
pass