Skip to content

Instantly share code, notes, and snippets.

@amirouche
Created April 30, 2015 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirouche/2e3a3ac14c4e0cc4568a to your computer and use it in GitHub Desktop.
Save amirouche/2e3a3ac14c4e0cc4568a to your computer and use it in GitHub Desktop.
Declarative syntax #hypermove #python #python3
class Property:
def __init__(self, *variables, **options):
self.variables = variables
self.options = options
self.name = None
def __get__(self, obj, klass):
print(obj)
return obj._values[self.name]
def __set__(self, obj, value):
print(obj)
obj._values[self.name] = value
class Meta(type):
def __new__(klass, name, bases, attributes):
klass._properties = dict()
for name, attribute in attributes.items():
if isinstance(attribute, Property):
attribute.name = name
klass._properties[name] = attribute
return super().__new__(
klass,
name,
bases,
attributes
)
class Model(metaclass=Meta):
def __init__(self):
self._values = dict()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment