Skip to content

Commit

Permalink
Fix: SWIG dict.get() should have optional default value parameter (#413)
Browse files Browse the repository at this point in the history
* Fix: swig dict get should have optional default value parameter
* Add test
  • Loading branch information
qiluo-msft authored Nov 12, 2020
1 parent 91e484d commit 40b255b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyext/swsscommon.i
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
%template(VectorString) std::vector<std::string>;

%pythoncode %{
def _FieldValueMap__get(self, key, defval):
def _FieldValueMap__get(self, key, default=None):
if key in self:
return self[key]
else:
return defval
return default

def _FieldValueMap__update(self, *args, **kwargs):
other = dict(*args, **kwargs)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_redis_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def test_DBInterface():
assert fvs["field1"] == "value2"

# Test dict.get()
assert fvs.get("field1") == "value2"
assert fvs.get("field1_noexisting") == None
assert fvs.get("field1", "default") == "value2"
assert fvs.get("nonfield", "default") == "default"

Expand Down

0 comments on commit 40b255b

Please sign in to comment.