Raymond Hettinger
88a9164cdb
Backport 70106: Add OrderedDict support to collections.namedtuple().
2009-03-03 04:51:24 +00:00
Raymond Hettinger
bc512d3abd
Backport PEP 372: OrderedDict()
2009-03-03 04:45:34 +00:00
Raymond Hettinger
322daea7c3
Issue 1818: collections.namedtuple() to support automatic renaming of invalid fieldnames.
2009-02-10 01:24:05 +00:00
Raymond Hettinger
ecf252abac
Issue 5021: doctest.testfile should set __name__
2009-01-27 10:03:04 +00:00
Raymond Hettinger
1bc1c8ac76
Update comments and add an optimized path for Counter.update().
2009-01-22 09:05:43 +00:00
Raymond Hettinger
4571f347f9
Simplify explanation of multiset operations by removing restrictions on negative inputs.
2009-01-21 20:31:50 +00:00
Raymond Hettinger
ae3f068fb5
Make merging easier by formattng comment blocks the same in Py3.1
2009-01-20 03:36:36 +00:00
Raymond Hettinger
562a4ada56
Add Counter() to __all__.
2009-01-20 02:24:38 +00:00
Raymond Hettinger
bad1eb2ff3
Build-outs for Counter() class:
...
* Constructor and update() support keyword args (like their dict counterparts).
* The 'del' statement no longer raises KeyError for missing values.
* Add multiset operations: __add__, __sub__, __and__, __or__.
2009-01-20 01:19:26 +00:00
Raymond Hettinger
35288c6b6c
Speed-up __repr__. Eliminate duplicate tests. Use a from-irmport.
2009-01-13 04:50:35 +00:00
Raymond Hettinger
783d73fc2f
Fixup and simplify docstrings and doctests.
2009-01-13 04:13:53 +00:00
Raymond Hettinger
aaa6e630f8
Simplify Counter() API. Replace items keyword argument
...
with a mapping. Makes Counter() idempotent, makes update()
API the same as Counter.__init__(), makes a more readable
repr, makes the API more dict-like, and allows Steven
Bethard's update() example to work.
2009-01-13 01:05:03 +00:00
Raymond Hettinger
f94d7fa5fb
Issue 1696199: Add collections.Counter().
2009-01-12 22:58:41 +00:00
Raymond Hettinger
6ee7bc04f7
Fix namedtuple bug reported by Glenn Linderman. Template did not form correctly if the field names were input in Unicode.
2008-09-25 23:31:52 +00:00
Raymond Hettinger
e98839a1f4
Issue3065: Fixed pickling of named tuples. Added tests.
2008-06-09 01:28:30 +00:00
Raymond Hettinger
3c2523c2eb
Issue 2903: Add __name__ in globals for namedtuple namespace.
2008-05-30 07:16:53 +00:00
Raymond Hettinger
15b5e55b48
Neaten-up the named tuple docs
2008-01-10 23:00:01 +00:00
Raymond Hettinger
e850c466c7
Clarify how to add a field to a named tuple.
2008-01-10 20:37:12 +00:00
Raymond Hettinger
e1655088ca
Examples for named tuple subclassing should include __slots__
2008-01-10 19:15:10 +00:00
Raymond Hettinger
581671419f
Expand comment.
2008-01-08 02:02:05 +00:00
Raymond Hettinger
f5e8af1bb7
Use get() instead of pop() for the optimized version of _replace().
2008-01-07 20:56:05 +00:00
Raymond Hettinger
9a359210aa
Cleanup named tuple subclassing example.
2008-01-07 20:07:38 +00:00
Raymond Hettinger
dc55f35f38
Add another named tuple subclassing example.
2008-01-07 09:03:49 +00:00
Raymond Hettinger
1db6f80cd5
Cleanup subclassing example to more clearly show fixed-width print format.
2008-01-07 05:50:35 +00:00
Raymond Hettinger
b8e0072fec
Add subclassing example to docs for named tuples.
2008-01-07 04:24:49 +00:00
Raymond Hettinger
844f71b7e4
Speed-up named tuple's _make() constructor.
2008-01-06 22:11:54 +00:00
Raymond Hettinger
1166872006
Small code simplification. Forgot that classmethods can be called from intances.
2008-01-06 09:02:24 +00:00
Raymond Hettinger
1b50fd7cb3
Add error-checking to namedtuple's _replace() method.
2008-01-05 02:17:24 +00:00
Raymond Hettinger
02740f73ff
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
2008-01-05 01:35:43 +00:00
Raymond Hettinger
e0734e7dc0
Minor fix-ups to named tuples:
...
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
2008-01-04 03:22:53 +00:00
Raymond Hettinger
85dfcf3530
Users demand iterable input for named tuples. The author capitulates.
2007-12-18 23:51:15 +00:00
Raymond Hettinger
8777bcae27
Simplify and speedup _asdict() for named tuples.
2007-12-18 22:21:27 +00:00
Raymond Hettinger
88880b2dd6
Add more namedtuple() test cases. Neaten the code and comments.
2007-12-18 00:13:45 +00:00
Raymond Hettinger
07ae83f840
Faster and simpler _replace() method
2007-12-14 19:19:59 +00:00
Raymond Hettinger
48eca67ab9
Add line spacing for readability
2007-12-14 18:08:20 +00:00
Raymond Hettinger
42da874cdd
Cleaner method naming convention
2007-12-14 02:49:47 +00:00
Raymond Hettinger
bc288e8bbd
Small speedup
2007-12-13 23:52:59 +00:00
Raymond Hettinger
04a9a0e904
Simplify implementation of __replace__()
2007-12-13 22:55:52 +00:00
Raymond Hettinger
2e1af256d4
Error checking was too aggressive (reported by Chris Tismer)
2007-12-05 18:11:08 +00:00
Guido van Rossum
64c06e327d
Backport of _abccoll.py by Benjamin Arangueren, issue 1383.
...
With some changes of my own thrown in (e.g. backport of r58107).
2007-11-22 00:55:51 +00:00
Raymond Hettinger
5681cbce81
Small improvement to the implementation of __replace__().
2007-11-15 02:55:42 +00:00
Raymond Hettinger
eeeb9c4445
Accept Issac Morland's suggestion for __replace__ to allow multiple replacements
...
(suprisingly, this simplifies the signature, improves clarity, and is comparably fast).
Update the docs to reflect a previous change to the function name.
Add an example to the docs showing how to override the default __repr__ method.
2007-11-15 02:44:53 +00:00
Raymond Hettinger
78f27e001b
Make __fields__ read-only. Suggested by Issac Morland
2007-11-14 22:56:16 +00:00
Raymond Hettinger
01a0957f06
Shorter name for namedtuple()
2007-10-23 20:37:41 +00:00
Raymond Hettinger
abfd8dff3b
More docs, error messages, and tests
2007-10-16 21:28:32 +00:00
Raymond Hettinger
050afbf214
Improve error messages
2007-10-16 19:18:30 +00:00
Raymond Hettinger
163f622c03
Make the error messages more specific
2007-10-09 01:36:23 +00:00
Raymond Hettinger
a48a29947a
Eliminate camelcase function name
2007-10-08 21:26:58 +00:00
Raymond Hettinger
0e1d606116
Better variable names
2007-10-08 10:11:51 +00:00
Raymond Hettinger
2115bbc4da
Add comments to NamedTuple code.
...
Let the field spec be either a string or a non-string sequence (suggested by Martin Blais with use cases).
Improve the error message in the case of a SyntaxError (caused by a duplicate field name).
2007-10-08 09:14:28 +00:00
Raymond Hettinger
a7fc4b13e0
Add __asdict__() to NamedTuple and refine the docs.
...
Add maxlen support to deque() and fixup docs.
Partially fix __reduce__(). The None as a third arg was no longer supported.
Still needs work on __reduce__() to handle recursive inputs.
2007-10-05 02:47:07 +00:00
Raymond Hettinger
2b03d45bb9
Handle corner cased on 0-tuples and 1-tuples. Add verbose option so people can see how it works.
2007-09-18 03:33:19 +00:00
Raymond Hettinger
d36a60e1e3
Sync-up named tuples with the latest version of the ASPN recipe.
...
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
2007-09-17 00:55:00 +00:00
Raymond Hettinger
767debb6aa
Allow all alphanumeric and underscores in type and field names.
2007-05-21 16:40:10 +00:00
Raymond Hettinger
0d6a8ccfb7
Replace assertion with straight error-checking.
2007-05-21 08:13:35 +00:00
Raymond Hettinger
f3241a3727
Fix beginner mistake -- don't mix spaces and tabs.
2007-05-19 01:50:11 +00:00
Raymond Hettinger
5a41daf096
Improvements to NamedTuple's implementation, tests, and documentation
2007-05-19 01:11:16 +00:00
Raymond Hettinger
c37e5e04eb
Add collections.NamedTuple
2007-03-01 06:16:43 +00:00
Raymond Hettinger
eb9798892d
Prepare collections module for pure python code entries.
2007-02-28 18:37:52 +00:00