Skip to content

Commit e13a11e

Browse files
committed
Fix dict bug
[SVN r16866]
1 parent 72b214b commit e13a11e

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

src/dict.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ object dict_base::get(object_cref k) const
6565
{
6666
if (check_exact(this))
6767
{
68-
return object(detail::borrowed_reference(
69-
PyDict_GetItem(this->ptr(),k.ptr())));
68+
PyObject* result = PyDict_GetItem(this->ptr(),k.ptr());
69+
return object(detail::borrowed_reference(result ? result : Py_None));
7070
}
7171
else
7272
{

test/dict.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void test_templates(object print)
6161
//print(tmp[1]);
6262
tmp[1.5] = 13;
6363
print(tmp.get(1.5));
64+
print(tmp.get(44));
6465
print(tmp);
6566
print(tmp.get(2,"default"));
6667
print(tmp.has_key(key));

test/dict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
>>> test_templates(printer)
2121
a test string
2222
13
23+
None
2324
{1.5: 13, 1: 'a test string'}
2425
default
2526
0

0 commit comments

Comments
 (0)