Commit Graph

80 Commits

Author SHA1 Message Date
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