summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_functools.py
diff options
context:
space:
mode:
authorMichael Seifert <michaelseifert04@yahoo.de>2017-03-15 07:42:02 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-03-15 07:42:02 (GMT)
commit53b2667dcf2a7d13af466a5fb91844f5125a920d (patch)
treedb0a2a111d9c9d361676abdfca7974291304d732 /Lib/test/test_functools.py
parentfaa2cc63e45bc7d7ffab84bebe5a9f4fe065bd96 (diff)
downloadcpython-53b2667dcf2a7d13af466a5fb91844f5125a920d.zip
cpython-53b2667dcf2a7d13af466a5fb91844f5125a920d.tar.gz
cpython-53b2667dcf2a7d13af466a5fb91844f5125a920d.tar.bz2
bpo-29800: Fix crashes in partial.__repr__ if the keys of partial.keywords are not strings (#649) (#671)
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r--Lib/test/test_functools.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index b7d648d..cd4664c 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -402,6 +402,32 @@ class TestPartialC(TestPartial, unittest.TestCase):
else:
self.fail('partial object allowed __dict__ to be deleted')
+ def test_manually_adding_non_string_keyword(self):
+ p = self.partial(capture)
+ # Adding a non-string/unicode keyword to partial kwargs
+ p.keywords[1234] = 'value'
+ r = repr(p)
+ self.assertIn('1234', r)
+ self.assertIn("'value'", r)
+ with self.assertRaises(TypeError):
+ p()
+
+ def test_keystr_replaces_value(self):
+ p = self.partial(capture)
+
+ class MutatesYourDict(object):
+ def __str__(self):
+ p.keywords[self] = ['sth2']
+ return 'astr'
+
+ # Raplacing the value during key formatting should keep the original
+ # value alive (at least long enough).
+ p.keywords[MutatesYourDict()] = ['sth']
+ r = repr(p)
+ self.assertIn('astr', r)
+ self.assertIn("['sth']", r)
+
+
class TestPartialPy(TestPartial, unittest.TestCase):
partial = py_functools.partial