Created
January 3, 2019 11:06
-
-
Save fcracker79/c99359a0cf4b668ab2787c6b8273c9fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def a_default_value(): | |
return 1 | |
def b_default_value(): | |
return 'hello' | |
def c_default_value(): | |
# Beware of immutable object | |
return frozenset(('x', 'y', 'z')) | |
class foo: | |
_DEFAULT_VALUES = { | |
'a': a_default_value(), | |
'b': b_default_value(), | |
'c': c_default_value() | |
} | |
def __init__(self, **kw): | |
for k in set(itertools.chain(kw.keys(), self._DEFAULT_VALUES.keys())): | |
setattr(self, k, kw[k] if k in kw else self._DEFAULT_VALUES[k]) | |
# assert sanity_check(a,b,c) | |
print(foo().c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment