1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class MetaProperty(type):
'''Classes which have this class as metaclass
will must have a get and a set method, they will
become properties, not classes.
The goal of this metaclass is purely esthetic'''
def __new__(cls,nm,bs,at):
if nm=='Prop':
return type.__new__(cls,nm,bs,at)
else:
return property(fget=(at['get'] if 'get' in at else None),
fset=(at['set'] if 'set' in at else None))
class Prop(object):
'''to be quicker, the properties created via
metaclass MetaProperty, can inherit from this
class instead of defining the __metaclass__
attribute'''
__metaclass__=MetaProperty |
Partager