[Python-checkins] python/dist/src/Lib UserDict.py,1.19,1.20
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Thu, 21 Nov 2002 16:07:42 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv17523
Modified Files:
UserDict.py
Log Message:
Implement dict() style constructor.
Already supported dict() and dict(mapping).
Now supports dict(itemsequence) and
Just van Rossum's new syntax for dict(keywordargs).
Also, added related unittests.
The docs already promise dict-like behavior
so no update is needed there.
Index: UserDict.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/UserDict.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** UserDict.py 18 Nov 2002 04:34:10 -0000 1.19
--- UserDict.py 22 Nov 2002 00:07:39 -0000 1.20
***************
*** 2,8 ****
class UserDict:
! def __init__(self, dict=None):
! self.data = {}
! if dict is not None: self.update(dict)
def __repr__(self): return repr(self.data)
def __cmp__(self, dict):
--- 2,13 ----
class UserDict:
! def __init__(self, dict=None, **kwargs):
! self.data = kwargs # defaults to {}
! if dict is not None:
! if hasattr(dict,'keys'): # handle mapping (possibly a UserDict)
! self.update(dict)
! else: # handle sequence
! DICT = type({}) # because builtin dict is locally overridden
! self.data.update(DICT(dict))
def __repr__(self): return repr(self.data)
def __cmp__(self, dict):