From 21a5825e6ec83f9f7a36461c995c6ac9df28b186 Mon Sep 17 00:00:00 2001 From: David Halter Date: Thu, 17 May 2012 10:49:52 +0200 Subject: [PATCH] property compatibility python 2.5 --- _compatibility.py | 24 ++++++++++++++++++++++++ evaluate.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/_compatibility.py b/_compatibility.py index 0ce7ee8a..5cb8adc8 100644 --- a/_compatibility.py +++ b/_compatibility.py @@ -24,3 +24,27 @@ try: from ast import literal_eval except ImportError: literal_eval = eval + + +# properties in 2.5 +try: + property.setter +except AttributeError: + import sys + + class property(property): + def __init__(self, fget, *args, **kwargs): + self.__doc__ = fget.__doc__ + super(property, self).__init__(fget, *args, **kwargs) + + def setter(self, fset): + cls_ns = sys._getframe(1).f_locals + for k, v in cls_ns.iteritems(): + if v == self: + propname = k + break + cls_ns[propname] = property(self.fget, fset, + self.fdel, self.__doc__) + return cls_ns[propname] +else: + property = property diff --git a/evaluate.py b/evaluate.py index 2c9fe72c..a316c42d 100644 --- a/evaluate.py +++ b/evaluate.py @@ -13,7 +13,7 @@ TODO class decorators TODO annotations ? how ? type evaluation and return? TODO nonlocal statement """ -from _compatibility import next +from _compatibility import next, property import itertools import copy