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
54628fa7
Commit
54628fa7
authored
Aug 04, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 6637: defaultdict.copy() failed with an empty factory.
parent
fe800a34
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
1 deletion
+11
-1
Lib/test/test_defaultdict.py
Lib/test/test_defaultdict.py
+7
-0
Modules/_collectionsmodule.c
Modules/_collectionsmodule.c
+4
-1
No files found.
Lib/test/test_defaultdict.py
View file @
54628fa7
...
...
@@ -60,6 +60,7 @@ class TestDefaultDict(unittest.TestCase):
d1
=
defaultdict
()
self
.
assertEqual
(
d1
.
default_factory
,
None
)
self
.
assertEqual
(
repr
(
d1
),
"defaultdict(None, {})"
)
self
.
assertEqual
(
eval
(
repr
(
d1
)),
d1
)
d1
[
11
]
=
41
self
.
assertEqual
(
repr
(
d1
),
"defaultdict(None, {11: 41})"
)
d2
=
defaultdict
(
int
)
...
...
@@ -112,6 +113,12 @@ class TestDefaultDict(unittest.TestCase):
d4
[
12
]
self
.
assertEqual
(
d4
,
{
42
:
[],
12
:
[]})
# Issue 6637: Copy fails for empty default dict
d
=
defaultdict
()
d
[
'a'
]
=
42
e
=
d
.
copy
()
self
.
assertEqual
(
e
[
'a'
],
42
)
def
test_shallow_copy
(
self
):
d1
=
defaultdict
(
foobar
,
{
1
:
1
})
d2
=
copy
.
copy
(
d1
)
...
...
Modules/_collectionsmodule.c
View file @
54628fa7
...
...
@@ -1170,6 +1170,9 @@ defdict_copy(defdictobject *dd)
whose class constructor has the same signature. Subclasses that
define a different constructor signature must override copy().
*/
if
(
dd
->
default_factory
==
NULL
)
return
PyObject_CallFunctionObjArgs
((
PyObject
*
)
Py_TYPE
(
dd
),
Py_None
,
dd
,
NULL
);
return
PyObject_CallFunctionObjArgs
((
PyObject
*
)
Py_TYPE
(
dd
),
dd
->
default_factory
,
dd
,
NULL
);
}
...
...
@@ -1316,7 +1319,7 @@ defdict_init(PyObject *self, PyObject *args, PyObject *kwds)
Py_ssize_t
n
=
PyTuple_GET_SIZE
(
args
);
if
(
n
>
0
)
{
newdefault
=
PyTuple_GET_ITEM
(
args
,
0
);
if
(
!
PyCallable_Check
(
newdefault
))
{
if
(
!
PyCallable_Check
(
newdefault
)
&&
newdefault
!=
Py_None
)
{
PyErr_SetString
(
PyExc_TypeError
,
"first argument must be callable"
);
return
-
1
;
...
...
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