Repository: Infinidat/munch

Issue:
DefaultMunch getter now returns None instead of DefaultValue
If a DefaultMunch has a default value of None, munch.get(attr_name, default_value) will now return None instead of default_value

```
>>> from munch import DefaultMunch
>>> d = DefaultMunch(None, {'a': 1})
>>> d.get('a')
1
>>> d.get('b')
>>> d.get('b', 'test')
>>> d.get('b', 'test') is None
True
```

This is a devastating change in behavior from the previous version:
```
>>> from munch import DefaultMunch
>>> d = DefaultMunch(None, {'a': 1})
>>> d.get('a')
1
>>> d.get('b')
>>> d.get('b', 'test')
'test'
>>> d.get('b', 'test') is None
False
```

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 424148a..723ba37 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@ Changelog
 
 Next Version
 ------------
+* Fix return value of DefaultMunch and DefaultFactoryMunch's get method (fixes [#53](https://github.com/Infinidat/munch/issues/53))
 
 2.4.0 (2019-10-29)
 ------------------
diff --git a/munch/__init__.py b/munch/__init__.py
index 83420a4..b668fc3 100644
--- a/munch/__init__.py
+++ b/munch/__init__.py
@@ -238,10 +238,9 @@ class Munch(dict):
         """
         D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.
         """
-        try:
-            return self[k]
-        except KeyError:
+        if k not in self:
             return d
+        return self[k]
 
     def setdefault(self, k, d=None):
         """


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 259071a..45d6b23 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,4 +1,5 @@
 import pytest
+import munch
 
 
 @pytest.fixture(name='yaml')
@@ -9,3 +10,12 @@ def yaml_module():
     except ImportError:
         pass
     pytest.skip("Module 'PyYAML' is required")
+
+
+@pytest.fixture(params=[munch.Munch, munch.AutoMunch, munch.DefaultMunch, munch.DefaultFactoryMunch])
+def munch_obj(request):
+    cls = request.param
+    args = tuple()
+    if cls == munch.DefaultFactoryMunch:
+        args = args + (lambda: None,)
+    return cls(*args, hello="world", number=5)
diff --git a/tests/test_munch.py b/tests/test_munch.py
index fc55165..9c645cc 100644
--- a/tests/test_munch.py
+++ b/tests/test_munch.py
@@ -533,3 +533,7 @@ def test_getitem_dunder_for_subclass():
     assert custom_munch.a == 42
     assert custom_munch.get('b') == 42
     assert custom_munch.copy() == Munch(a=42, b=42)
+
+
+def test_get_default_value(munch_obj):
+    assert munch_obj.get("fake_key", "default_value") == "default_value"