Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/moin/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ def __getitem__(self, item):
"""Make it possible to access a config object like a dict"""
return getattr(self, item)

def get(self, item, default=None):
"""Dict-like get method.
Return the value for key if key is in the dictionary, else default.
If default is not given, it defaults to None, so that this method never raises a KeyError."""
try:
return getattr(self, item)
except AttributeError:
return default

Comment on lines +269 to +277
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the idea of the DefaultConfig is that it has defaults for all supported attributes, so one would never get this AttributeError.

Having it in this class is also useful because it is one place where settings and their default can be looked up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


class DefaultConfig(ConfigFunctionality):
"""Configuration base class with default config values
Expand Down
Loading