Ticket #191: property_attributeerror.patch
| File property_attributeerror.patch, 1.7 KB (added by michele, 4 years ago) |
|---|
-
template/tests/eval.py
345 345 def prop(self): 346 346 raise NotImplementedError 347 347 prop = property(prop) 348 def another_prop(self): 349 raise AttributeError 350 another_prop = property(another_prop) 351 class SomethingSubclass(Something): 352 pass 348 353 self.assertRaises(NotImplementedError, 349 354 Expression('s.prop').evaluate, {'s': Something()}) 355 self.assertRaises(AttributeError, 356 Expression('s.another_prop').evaluate, 357 {'s': SomethingSubclass()}) 350 358 351 359 def test_getitem_undefined_string(self): 352 360 class Something(object): -
template/eval.py
272 272 273 273 def lookup_attr(cls, data, obj, key): 274 274 __traceback_hide__ = True 275 val = getattr(obj, key, UNDEFINED) 276 if val is UNDEFINED: 277 try: 278 val = obj[key] 279 except (KeyError, TypeError): 280 val = cls.undefined(key, owner=obj) 275 try: 276 val = getattr(obj, key) 277 except AttributeError: 278 # see ticket #191 279 if hasattr(obj.__class__, key): 280 raise 281 else: 282 try: 283 val = obj[key] 284 except (KeyError, TypeError): 285 val = cls.undefined(key, owner=obj) 281 286 return val 282 287 lookup_attr = classmethod(lookup_attr) 283 288
