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
e03e5b1f
Commit
e03e5b1f
authored
Dec 07, 2002
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove assumption that cls is a subclass of dict.
Simplifies the code and gets Just van Rossum's example to work.
parent
4e52ca82
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
10 deletions
+4
-10
Lib/test/test_types.py
Lib/test/test_types.py
+3
-3
Objects/dictobject.c
Objects/dictobject.c
+1
-7
No files found.
Lib/test/test_types.py
View file @
e03e5b1f
...
...
@@ -566,9 +566,9 @@ from UserDict import UserDict
class
mydict
(
dict
):
def
__new__
(
cls
,
*
args
,
**
kwargs
):
return
UserDict
(
*
args
,
**
kwargs
)
try
:
mydict
.
fromkeys
(
'a b c'
.
split
()
)
except
TypeError
:
pass
else
:
raise
TestFailed
,
'dict.fromkeys() failed to detect non-dict class.
'
ud
=
mydict
.
fromkeys
(
'ab'
)
if
ud
!=
{
'a'
:
None
,
'b'
:
None
}
or
not
isinstance
(
ud
,
UserDict
):
raise
TestFailed
,
'fromkeys did not instantiate using __new__
'
# dict.copy()
d
=
{
1
:
1
,
2
:
2
,
3
:
3
}
if
d
.
copy
()
!=
{
1
:
1
,
2
:
2
,
3
:
3
}:
raise
TestFailed
,
'dict copy'
...
...
Objects/dictobject.c
View file @
e03e5b1f
...
...
@@ -979,12 +979,6 @@ dict_fromkeys(PyObject *mp, PyObject *args)
d
=
PyObject_CallObject
(
cls
,
NULL
);
if
(
d
==
NULL
)
return
NULL
;
if
(
!
PyDict_Check
(
d
))
{
Py_DECREF
(
d
);
PyErr_SetString
(
PyExc_TypeError
,
"class constructor must return a subclass of dict"
);
return
NULL
;
}
it
=
PyObject_GetIter
(
seq
);
if
(
it
==
NULL
){
...
...
@@ -999,7 +993,7 @@ dict_fromkeys(PyObject *mp, PyObject *args)
goto
Fail
;
break
;
}
status
=
Py
Di
ct_SetItem
(
d
,
key
,
value
);
status
=
Py
Obje
ct_SetItem
(
d
,
key
,
value
);
Py_DECREF
(
key
);
if
(
status
<
0
)
goto
Fail
;
...
...
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