You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Need a way to tell Munch to throw an exception (AttributeError or something) when an attribute is missing. Today, it returns None, or you can set a default value, but you can't configure it to throw an exception.
Why is this important?
Munchified dictionaries don't work with existing getattr() calls
Say you have existing code without munch that does this:
foo = getattr(conf, 'foo', 1)
If conf['foo'] does not exist, foo gets set to 1
Now, lets say you munchify conf (so that you can easily access the fields). This will break existing getattrs. Using the same code:
Now, id conf['foo'] does not exist, BUT foo gets set to None. This breaks any existing code that was using getattr(). getattr() is a very commonly used for dict access and specifying default values.
We need a way to use the ease of accessing fields, but still throw an exception on missing attributes
The text was updated successfully, but these errors were encountered:
roubles
changed the title
Need undefined exception thrown for missing attributes
Need exception thrown for missing attributes
Jan 6, 2023
Need a way to tell Munch to throw an exception (AttributeError or something) when an attribute is missing. Today, it returns None, or you can set a default value, but you can't configure it to throw an exception.
Why is this important?
Munchified dictionaries don't work with existing getattr() calls
Say you have existing code without munch that does this:
If conf['foo'] does not exist, foo gets set to 1
Now, lets say you munchify conf (so that you can easily access the fields). This will break existing getattrs. Using the same code:
Now, id conf['foo'] does not exist, BUT foo gets set to None. This breaks any existing code that was using getattr(). getattr() is a very commonly used for dict access and specifying default values.
We need a way to use the ease of accessing fields, but still throw an exception on missing attributes
The text was updated successfully, but these errors were encountered: