summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_functools.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-09-22 10:08:16 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2015-09-22 10:08:16 (GMT)
commit9b93c6b5dfe0b6bab4392e88409bf4f72c2570d5 (patch)
tree721db74495c08e381e3ef1a2e2d4bc11c0553788 /Lib/test/test_functools.py
parent5e202086a5261f727b16ec8a5d5bf73046df1b12 (diff)
downloadcpython-9b93c6b5dfe0b6bab4392e88409bf4f72c2570d5.zip
cpython-9b93c6b5dfe0b6bab4392e88409bf4f72c2570d5.tar.gz
cpython-9b93c6b5dfe0b6bab4392e88409bf4f72c2570d5.tar.bz2
Issue #25137: Add a note to whatsnew/3.5.rst for nested functools.partial calls
Also, properly skip the test_nested_optimization test for partial subclasses and add a test for the suggested usage.
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r--Lib/test/test_functools.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index ae929ec..7ecf877 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -139,14 +139,23 @@ class TestPartial:
def test_nested_optimization(self):
partial = self.partial
- # Only "true" partial is optimized
- if partial.__name__ != 'partial':
- return
inner = partial(signature, 'asdf')
nested = partial(inner, bar=True)
flat = partial(signature, 'asdf', bar=True)
self.assertEqual(signature(nested), signature(flat))
+ def test_nested_partial_with_attribute(self):
+ # see issue 25137
+ partial = self.partial
+
+ def foo(bar):
+ return bar
+
+ p = partial(foo, 'first')
+ p2 = partial(p, 'second')
+ p2.new_attr = 'spam'
+ self.assertEqual(p2.new_attr, 'spam')
+
@unittest.skipUnless(c_functools, 'requires the C _functools module')
class TestPartialC(TestPartial, unittest.TestCase):
@@ -238,6 +247,9 @@ class TestPartialCSubclass(TestPartialC):
if c_functools:
partial = PartialSubclass
+ # partial subclasses are not optimized for nested calls
+ test_nested_optimization = None
+
class TestPartialMethod(unittest.TestCase):