Commit Graph

35 Commits

Author SHA1 Message Date
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
Fred Drake bedebbdfb1 Added support for .iteritems(), .iterkeys(), .itervalues(). 2001-05-03 04:54:41 +00:00
Tim Peters a3f98d6bac Give UserDict new __contains__ and __iter__ methods. 2001-04-21 09:13:15 +00:00
Skip Montanaro 78349072f7 removed __all__ from several modules 2001-02-18 03:30:53 +00:00
Skip Montanaro e99d5ea25b added __all__ lists to a number of Python modules
added test script and expected output file as well
this closes patch 103297.
__all__ attributes will be added to other modules without first submitting
a patch, just adding the necessary line to the test script to verify
more-or-less correct implementation.
2001-01-20 19:54:20 +00:00
Guido van Rossum 1072c3872d Add popitem(). 2000-12-12 22:06:00 +00:00
Guido van Rossum 164452cec4 Barry's patch to implement the new setdefault() method. 2000-08-08 16:12:54 +00:00
Guido van Rossum 4acc25bd39 Mass patch by Ka-Ping Yee:
1. Comments at the beginning of the module, before
       functions, and before classes have been turned
       into docstrings.

    2. Tabs are normalized to four spaces.

Also, removed the "remove" function from dircmp.py, which reimplements
list.remove() (it must have been very old).
2000-02-02 15:10:15 +00:00
Guido van Rossum 1697b9cdf6 Improved a bunch of things.
The constructor now takes an optional dictionary.
Use isinstance() where appropriate.
1999-03-26 15:31:12 +00:00
Guido van Rossum 45e2fbc2e7 Mass check-in after untabifying all files that need it. 1998-03-26 21:13:24 +00:00
Barry Warsaw fc3e61cd28 UserDict.get(): New method to mirror built-in dictionaries' get()
method.
1997-10-06 17:50:04 +00:00
Guido van Rossum b94cd96977 Fix bug in copy() by using copy.copy() instead of making assumptions
(it so happens that copy.copy() works fine for the base UserDict
type).  Also reindented the entire module to have 4-space indents.
1997-06-03 14:10:01 +00:00
Fred Drake bd40d7e69f Added the new dictionary methods to the wrapper class. 1997-06-03 13:07:59 +00:00
Guido van Rossum ae3b3a33d8 * test_*.py: new lambda syntax (also affects tests for filter, map,
reduce)
* ftplib.py: added default callback for retrlines; added dir() method
* ftplib.py: don't return self in self.connect(); added hack so that if
  'CDUP' is not understood, 'CWD ..' is tried.
* ftplib.py: second method called init() should have been called
  connect(); if __init__ sees more than one argument, it will also try to
  login().
1993-11-30 13:43:54 +00:00