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
db780d0d
Commit
db780d0d
authored
Apr 23, 2012
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix instance dicts with str subclasses (#13903)
parent
53b97712
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
Lib/test/test_dict.py
Lib/test/test_dict.py
+10
-0
Objects/dictobject.c
Objects/dictobject.c
+5
-1
No files found.
Lib/test/test_dict.py
View file @
db780d0d
...
@@ -879,6 +879,16 @@ class DictTest(unittest.TestCase):
...
@@ -879,6 +879,16 @@ class DictTest(unittest.TestCase):
values
=
list
(
it
)
+
[
drop
]
values
=
list
(
it
)
+
[
drop
]
self
.
assertEqual
(
sorted
(
values
),
sorted
(
list
(
data
.
values
())))
self
.
assertEqual
(
sorted
(
values
),
sorted
(
list
(
data
.
values
())))
def
test_instance_dict_getattr_str_subclass
(
self
):
class
Foo
:
def
__init__
(
self
,
msg
):
self
.
msg
=
msg
f
=
Foo
(
'123'
)
class
_str
(
str
):
pass
self
.
assertEqual
(
f
.
msg
,
getattr
(
f
,
_str
(
'msg'
)))
self
.
assertEqual
(
f
.
msg
,
f
.
__dict__
[
_str
(
'msg'
)])
from
test
import
mapping_tests
from
test
import
mapping_tests
class
GeneralMappingTests
(
mapping_tests
.
BasicTestMappingProtocol
):
class
GeneralMappingTests
(
mapping_tests
.
BasicTestMappingProtocol
):
...
...
Objects/dictobject.c
View file @
db780d0d
...
@@ -641,7 +641,11 @@ lookdict_split(PyDictObject *mp, PyObject *key,
...
@@ -641,7 +641,11 @@ lookdict_split(PyDictObject *mp, PyObject *key,
register
PyDictKeyEntry
*
ep
;
register
PyDictKeyEntry
*
ep
;
if
(
!
PyUnicode_CheckExact
(
key
))
{
if
(
!
PyUnicode_CheckExact
(
key
))
{
return
lookdict
(
mp
,
key
,
hash
,
value_addr
);
ep
=
lookdict
(
mp
,
key
,
hash
,
value_addr
);
/* lookdict expects a combined-table, so fix value_addr */
i
=
ep
-
ep0
;
*
value_addr
=
&
mp
->
ma_values
[
i
];
return
ep
;
}
}
i
=
(
size_t
)
hash
&
mask
;
i
=
(
size_t
)
hash
&
mask
;
ep
=
&
ep0
[
i
];
ep
=
&
ep0
[
i
];
...
...
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