Created
June 26, 2019 16:30
-
-
Save ncopiy/bb2a76b5d7295158b5347631dc98ad84 to your computer and use it in GitHub Desktop.
defaultattr (like defaultdict but for attributes)
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
class defaultattr: | |
def __init__(self, expected_type): | |
self.expected_type = expected_type | |
def __getattr__(self, expected_type): | |
if isinstance(self.expected_type, type): | |
return self.expected_type() | |
return self.expected_type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment