Last active
October 30, 2015 18:01
-
-
Save bbelyeu/7e64ea0f2e74d6a3958b 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
class StringProp(BaseDescriptor): | |
required = False | |
def __init__(self, default=None, required=False): | |
self.default = default | |
self.data = WeakKeyDictionary() | |
self.required = bool(required) | |
def __set__(self, instance, val): | |
if self.required and not val: | |
raise ValueError("Invalid value for required property: {0}".format(val)) | |
if not isinstance(val, basestring): | |
raise ValueError("Invalid string property: {0}".format(val)) | |
self.data[instance] = val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment