From 204653ff84848ae8c4c812bb4ddddbf172dbfe01 Mon Sep 17 00:00:00 2001 From: Jeff VanOss Date: Thu, 28 Dec 2017 19:22:08 -0500 Subject: [PATCH 1/2] fix return from std::map bindings to __delitem__ --- include/pybind11/stl_bind.h | 2 +- tests/test_stl_binders.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/pybind11/stl_bind.h b/include/pybind11/stl_bind.h index 7ef6878787..38dd68f695 100644 --- a/include/pybind11/stl_bind.h +++ b/include/pybind11/stl_bind.h @@ -587,7 +587,7 @@ class_ bind_map(handle scope, const std::string &name, Args&&. auto it = m.find(k); if (it == m.end()) throw key_error(); - return m.erase(it); + m.erase(it); } ); diff --git a/tests/test_stl_binders.py b/tests/test_stl_binders.py index bf1aa674c0..19817fff50 100644 --- a/tests/test_stl_binders.py +++ b/tests/test_stl_binders.py @@ -181,3 +181,24 @@ def test_noncopyable_containers(): vsum += v.value assert vsum == 150 + +def test_map_delitem(): + mm = m.MapStringDouble() + mm['a'] = 1 + mm['b'] = 2.5 + + assert list(mm) == ['a', 'b'] + assert list(mm.items()) == [('a', 1), ('b', 2.5)] + del mm['a'] + assert list(mm) == ['b'] + assert list(mm.items()) == [('b', 2.5)] + + um = m.UnorderedMapStringDouble() + um['ua'] = 1.1 + um['ub'] = 2.6 + + assert sorted(list(um)) == ['ua', 'ub'] + assert sorted(list(um.items())) == [('ua', 1.1), ('ub', 2.6)] + del um['ua'] + assert sorted(list(um)) == ['ub'] + assert sorted(list(um.items())) == [('ub', 2.6)] From b71e3b05d75a98c5cf607fa03d2c4c928a55e168 Mon Sep 17 00:00:00 2001 From: Jeff VanOss Date: Fri, 29 Dec 2017 09:25:07 -0500 Subject: [PATCH 2/2] flake8 formating --- tests/test_stl_binders.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_stl_binders.py b/tests/test_stl_binders.py index 19817fff50..0030924fb7 100644 --- a/tests/test_stl_binders.py +++ b/tests/test_stl_binders.py @@ -182,6 +182,7 @@ def test_noncopyable_containers(): assert vsum == 150 + def test_map_delitem(): mm = m.MapStringDouble() mm['a'] = 1