Commit Graph

38 Commits

Author SHA1 Message Date
Serhiy Storchaka
cab4566c5a Issue #22609: Constructor and the update method of collections.UserDict now
accept the self keyword argument.
2015-09-29 23:33:03 +03:00
Benjamin Peterson
bde67df0cd keep UserDict an old-style class
Be generous in abc.py to allow this.
2010-06-22 18:09:02 +00:00
Georg Brandl
84fedf7f06 No need to assign the results of expressions used only for side effects. 2010-02-06 22:59:15 +00:00
Benjamin Peterson
11fab6c07d avoid a py3k warning from __hash__ 2010-01-28 02:18:25 +00:00
Benjamin Peterson
17527bedad for UserDict to be compatible with abcs, it must subclass object 2010-01-27 02:15:28 +00:00
Georg Brandl
3bed4aeea5 Register IterableUserDict as a MutableMapping. 2008-06-07 16:16:12 +00:00
Raymond Hettinger
31ce5cb989 Update more instances of has_key(). 2008-02-21 19:24:53 +00:00
Guido van Rossum
8bc0965adf Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given.  More work like this needs to
be done in the rest of the stdlib.
2008-02-21 18:18:37 +00:00
Guido van Rossum
1968ad32cd - Patch 1433928:
- The copy module now "copies" function objects (as atomic objects).
  - dict.__getitem__ now looks for a __missing__ hook before raising
    KeyError.
  - Added a new type, defaultdict, to the collections module.
    This uses the new __missing__ hook behavior added to dict (see above).
2006-02-25 22:38:04 +00:00
Guido van Rossum
75b64e65f1 Use decorators. 2005-01-16 00:16:11 +00:00
Walter Dörwald
c139909611 The default argument in dict.setdefault() defaults to None.
Add this default to UserDict.DictMixin.setdefault() too.
2004-05-27 09:41:04 +00:00
Raymond Hettinger
31017aed36 SF #904720: dict.update should take a 2-tuple sequence like dict.__init_
(Championed by Bob Ippolito.)

The update() method for mappings now accepts all the same argument forms
as the dict() constructor.  This includes item lists and/or keyword
arguments.
2004-03-04 08:25:44 +00:00
Raymond Hettinger
9014560412 Make sure the UserDict copies do not share the same underlying
dictionary as the original.  This parallels MvL's change to
Lib/os.py 1.56.

Backport candidate.
2003-12-21 22:19:08 +00:00
Raymond Hettinger
f477c88450 SF bug #849662. Dramatically, improve comparison speed for "if shl == None". 2003-12-04 20:04:09 +00:00
Raymond Hettinger
a3e1e4cd79 SF patch #693753: fix for bug 639806: default for dict.pop
(contributed by Michael Stone.)
2003-03-06 23:54:28 +00:00
Barry Warsaw
1a17704ff1 typo in comment 2003-01-31 03:30:09 +00:00
Raymond Hettinger
51f3f1b7dc SF patch #667730: More DictMixin
Sebastien Keim pointed out that iterkeys and __contains__ require
their own definitions so their behavior will update when the
underlying method is subclassed.
2003-01-22 01:39:06 +00:00
Raymond Hettinger
e4827eb2a2 Bring UserDict in-sync with changes to dict.
Constructor accepts optional keyword arguments after a optional items list.
Add fromkeys() as an alternate constructor from an iterable over keys.
Expand related unittests.
2002-11-27 08:29:11 +00:00
Raymond Hettinger
54405456e5 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.
2002-11-22 00:07:40 +00:00
Raymond Hettinger
8ddc176e2e Improve DictMixin.
Replaced docstring with comments.  Prevents subclass contamination.
Added the missing __cmp__() method and a test for __cmp__().
Used try/except style in preference to has_key() followed by a look-up.
Used iteritem() where possible to save creating a long key list and
   to save redundant lookups.
Expanded .update() to look for the most helpful methods first and gradually
   work down to a mininum expected interface.
Expanded documentation to be more clear on how to use the class.
2002-11-18 04:34:10 +00:00
Raymond Hettinger
7994716b6b SF patch #520382: Expand shelve.py to have a full dictionary interface
and add a mixin to UserDict.py to make it easier to implement a full
dictionary interface.
2002-11-15 06:46:14 +00:00
Guido van Rossum
f49562586f Add pop() to UserDict. 2002-04-13 14:03:38 +00:00
Fred Drake
3ce5af70e3 copy(): Make sure the copy of a derived class cannot share the data of the
original by replacing self.data temporarily, then using the update() method
on the new mapping object to populate it.
This closes SF bug #476616.
2001-11-05 17:40:48 +00:00
Guido van Rossum
2050b65e84 Remove the __iter__ method from the UserDict class -- it can silently
break old code (in extreme cases).  See SF bug #448153.

Add a new subclass IterableUserDict that has the __iter__ method.

Note that for new projects, unless backwards compatibility with
pre-2.2 Python is required, subclassing 'dictionary' is recommended;
UserDict might become deprecated.
2001-08-07 17:40:42 +00:00
Martin v. Löwis
f3b30747d6 Patch #413171: Implement get, setdefault, update in terms of
has_key, __getitem__, and __setitem__.
2001-06-18 01:09:41 +00:00