Ticket #2620: 2620.patch

File 2620.patch, 975 bytes (added by shields@…, 9 years ago)
  • django/utils/datastructures.py

    old new  
     1class NoDefault(object):
     2    pass
     3
    14class MergeDict(object):
    25    """
    36    A simple class for creating new "virtual" dictionaries that actualy look
     
    1417                pass
    1518        raise KeyError
    1619
    17     def get(self, key, default):
     20    def get(self, key, default=NoDefault):
    1821        try:
    1922            return self[key]
    2023        except KeyError:
  • new file tests/othertests/datastructures.py

    - +  
     1from django.utils.datastructures import MergeDict
     2
     3dict1 = {'a': 1, 'b': 2}
     4dict2 = {'a': 10, 'c': 20}
     5
     6dictm = MergeDict(dict1, dict2)
     7assert dictm['a'] == 1
     8assert dictm['b'] == 2
     9assert dictm['c'] == 20
     10assert dictm.get('b') == 2
     11assert dictm.get('b', 7) == 2
     12assert dictm.get('x', 7) == 7
Back to Top