Django

Code

Ticket #4041: 4041.2.diff

File 4041.2.diff, 1.0 kB (added by SmileyChris, 2 years ago)

optimized version

  • django/core/cache/backends/base.py

    old new  
    5454        Returns True if the key is in the cache and has not expired. 
    5555        """ 
    5656        return self.get(key) is not None 
     57 
     58    # Allow use of 'in' operator. 
     59    __contains__ = has_key 
  • tests/regressiontests/cache/tests.py

    old new  
    4646        self.assertEqual(cache.has_key("hello"), True) 
    4747        self.assertEqual(cache.has_key("goodbye"), False) 
    4848 
     49    def test_in(self):  
     50        cache.set("hello", "goodbye")  
     51        self.assertEqual("hello" in cache, True)  
     52        self.assertEqual("goodbye" in cache, False)  
     53 
    4954    def test_data_types(self): 
    5055        # test data types 
    5156        stuff = {