diff options
author | Michael Seifert <michaelseifert04@yahoo.de> | 2017-03-15 05:26:33 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-15 05:26:33 (GMT) |
commit | 6c3d5274687c97f9c13800ad50e73e15b54f629d (patch) | |
tree | c76bba1b35b7200996e6b33002749c99621ddce4 /Lib/test/test_functools.py | |
parent | 024b4fdc4a981ec9ec17f2e63124ec542eb728ff (diff) | |
download | cpython-6c3d5274687c97f9c13800ad50e73e15b54f629d.zip cpython-6c3d5274687c97f9c13800ad50e73e15b54f629d.tar.gz cpython-6c3d5274687c97f9c13800ad50e73e15b54f629d.tar.bz2 |
bpo-29800: Fix crashes in partial.__repr__ if the keys of partial.keywords are not strings (#649)
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r-- | Lib/test/test_functools.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 612ca17..29ea493 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -403,6 +403,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 |