Edgewall Software

Ticket #191: property_attributeerror.patch

File property_attributeerror.patch, 1.7 KB (added by michele, 4 years ago)

the patch

  • template/tests/eval.py

     
    345345            def prop(self): 
    346346                raise NotImplementedError 
    347347            prop = property(prop) 
     348            def another_prop(self): 
     349                raise AttributeError 
     350            another_prop = property(another_prop) 
     351        class SomethingSubclass(Something): 
     352            pass 
    348353        self.assertRaises(NotImplementedError, 
    349354                          Expression('s.prop').evaluate, {'s': Something()}) 
     355        self.assertRaises(AttributeError, 
     356                          Expression('s.another_prop').evaluate, 
     357                          {'s': SomethingSubclass()}) 
    350358 
    351359    def test_getitem_undefined_string(self): 
    352360        class Something(object): 
  • template/eval.py

     
    272272 
    273273    def lookup_attr(cls, data, obj, key): 
    274274        __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) 
    281286        return val 
    282287    lookup_attr = classmethod(lookup_attr) 
    283288