Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6c3d5274
Commit
6c3d5274
authored
Mar 15, 2017
by
Michael Seifert
Committed by
Serhiy Storchaka
Mar 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29800: Fix crashes in partial.__repr__ if the keys of partial.keywords are not strings (#649)
parent
024b4fdc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
1 deletion
+34
-1
Lib/test/test_functools.py
Lib/test/test_functools.py
+26
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_functoolsmodule.c
Modules/_functoolsmodule.c
+4
-1
No files found.
Lib/test/test_functools.py
View file @
6c3d5274
...
...
@@ -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
...
...
Misc/ACKS
View file @
6c3d5274
No preview for this file type
Misc/NEWS
View file @
6c3d5274
...
...
@@ -281,6 +281,9 @@ Extension Modules
Library
-------
-
bpo
-
29800
:
Fix
crashes
in
partial
.
__repr__
if
the
keys
of
partial
.
keywords
are
not
strings
.
Patch
by
Michael
Seifert
.
-
bpo
-
8256
:
Fixed
possible
failing
or
crashing
input
()
if
attributes
"encoding"
or
"errors"
of
sys
.
stdin
or
sys
.
stdout
are
not
set
or
are
not
strings
.
...
...
Modules/_functoolsmodule.c
View file @
6c3d5274
...
...
@@ -297,8 +297,11 @@ partial_repr(partialobject *pto)
/* Pack keyword arguments */
assert
(
PyDict_Check
(
pto
->
kw
));
for
(
i
=
0
;
PyDict_Next
(
pto
->
kw
,
&
i
,
&
key
,
&
value
);)
{
Py_SETREF
(
arglist
,
PyUnicode_FromFormat
(
"%U, %U=%R"
,
arglist
,
/* Prevent key.__str__ from deleting the value. */
Py_INCREF
(
value
);
Py_SETREF
(
arglist
,
PyUnicode_FromFormat
(
"%U, %S=%R"
,
arglist
,
key
,
value
));
Py_DECREF
(
value
);
if
(
arglist
==
NULL
)
goto
done
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment