Commit Graph

46 Commits

Author SHA1 Message Date
Martin v. Löwis ad0a4629be Use Py_ssize_t for counts and sizes. 2006-02-16 14:30:23 +00:00
Armin Rigo f5b3e36493 Renamed _length_cue() to __length_hint__(). See:
http://mail.python.org/pipermail/python-dev/2006-February/060524.html
2006-02-11 21:32:43 +00:00
Neal Norwitz 1ac754fa10 Check return result from Py_InitModule*(). This API can fail.
Probably should be backported.
2006-01-19 06:09:39 +00:00
Jeremy Hylton af68c874a6 Add const to several API functions that take char *.
In C++, it's an error to pass a string literal to a char* function
without a const_cast().  Rather than require every C++ extension
module to put a cast around string literals, fix the API to state the
const-ness.

I focused on parts of the API where people usually pass literals:
PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type
slots, etc.  Predictably, there were a large set of functions that
needed to be fixed as a result of these changes.  The most pervasive
change was to make the keyword args list passed to
PyArg_ParseTupleAndKewords() to be a const char *kwlist[].

One cast was required as a result of the changes:  A type object
mallocs the memory for its tp_doc slot and later frees it.
PyTypeObject says that tp_doc is const char *; but if the type was
created by type_new(), we know it is safe to cast to char *.
2005-12-10 18:50:16 +00:00
Raymond Hettinger 6b27cda643 Convert iterator __len__() methods to a private API. 2005-09-24 21:23:05 +00:00
Georg Brandl 02c42871cf Disallow keyword arguments for type constructors that don't use them.
(fixes bug #1119418)
2005-08-26 06:42:30 +00:00
Raymond Hettinger b2594050ea Added optional None arguments to itertools.islice(). 2004-12-05 09:25:51 +00:00
Fred Drake 08ebfec75e some platforms still need offsetof() from structmember.h 2004-10-17 19:36:57 +00:00
Raymond Hettinger a9f6092904 Fix and test weak referencing of itertools.tee objects. 2004-10-17 16:40:14 +00:00
Raymond Hettinger 880430e2a5 Replace structure member before decreffing. 2004-10-02 10:56:43 +00:00
Raymond Hettinger 4cda01e260 * Increase test coverage.
* Have groupby() be careful about decreffing structure members.
2004-09-28 04:45:28 +00:00
Raymond Hettinger 75ccea3777 SF patch #1020188: Use Py_CLEAR where necessary to avoid crashes
(Contributed by Dima Dorfman)
2004-09-01 07:02:44 +00:00
Raymond Hettinger 58ed69b402 Exercise Jim's VISIT macro. 2004-07-15 05:32:47 +00:00
Raymond Hettinger 9d7c870c6d SF #950057: itertools.chain doesn't "process" exceptions as they occur
Both cycle() and chain() were handling exceptions only when switching
input sources.  The patch makes the handle more immediate.

Will backport.
2004-05-08 19:49:42 +00:00
Brett Cannon 0046839dd2 Change two instance of format strings for PyString_FromFormat() to use %ld
instead of %d .
2004-04-13 02:43:53 +00:00
Raymond Hettinger 7dacda2947 Provide more information representations of repeat() and count(). 2004-04-08 21:54:00 +00:00
Raymond Hettinger 0faa1ca51d Speedup the inner loops for dropwhile(), islice(), ifilter(), and
ifilterfalse().
2004-03-17 04:27:44 +00:00
Skip Montanaro f3938fd029 need to initialize ob_type slot at run-time, at least on cygwin 2004-02-10 20:27:40 +00:00
Raymond Hettinger 5cab2e3a88 Give itertools.repeat() a length method. 2004-02-10 09:25:40 +00:00
Raymond Hettinger d25c1c6351 Implement itertools.groupby()
Original idea by Guido van Rossum.
Idea for skipable inner iterators by Raymond Hettinger.
Idea for argument order and identity function default by Alex Martelli.
Implementation by Hye-Shik Chang (with tweaks by Raymond Hettinger).
2003-12-06 16:23:06 +00:00
Raymond Hettinger ad983e79d6 Improve the implementation of itertools.tee().
Formerly, underlying queue was implemented in terms of two lists.  The
new queue is a series of singly-linked fixed length lists.

The new implementation runs much faster, supports multi-way tees, and
allows tees of tees without additional memory costs.

The root ideas for this structure were contributed by Andrew Koenig
and Guido van Rossum.
2003-11-12 14:32:26 +00:00
Raymond Hettinger 0e4f76405d Fix nits in error messages. 2003-10-28 07:32:28 +00:00
Raymond Hettinger f0c5aec85f Minor improvements to itertools.tee():
* tee object is no longer subclassable
* independent iterators renamed to "itertools.tee_iterator"
* fixed doc string typo and added entry in the module doc string
2003-10-26 14:25:56 +00:00
Raymond Hettinger 4514369f27 Improvements to coding for itertools.tee():
* Add error checking code to PyList_Append() call.

* Replace PyObject_CallMethod(to->outbasket, "pop", NULL) with equivalent
  in-line code.  Inlining is important here because the search for the
  pop method will occur for every element returned by the iterator.

* Make tee's dealloc() a little smarter.  If the trailing iterator is
  being deallocated, then the queue data is no longer needed and can
  be freed.
2003-10-25 06:37:47 +00:00
Raymond Hettinger 6a5b027742 Added itertools.tee()
It works like the pure python verion except:
* it stops storing data after of the iterators gets deallocated
* the data queue is implemented with two stacks instead of one dictionary.
2003-10-24 08:45:23 +00:00
Raymond Hettinger 4f01f89b8c For safety, replace a tuple entry before decreffing it. 2003-08-30 00:10:06 +00:00
Raymond Hettinger a56f6b6600 SF bug #793826: using itertools.izip to mutate tuples
Avoid Armin Rigo's dastardly exercise in re-entrancy.
2003-08-29 23:09:58 +00:00
Raymond Hettinger b5a420883c Modified itertools.izip() to match the behavior of __builtin__.zip()
which can now take zero arguments.
2003-08-08 05:10:41 +00:00
Raymond Hettinger 1d7a3489e9 SF patch #770521: make itertools type declarations static
(Contributed by Andrew I MacIntyre.)
2003-07-14 07:07:12 +00:00
Raymond Hettinger befa37dd05 Minor updates:
* Updated comment on design of imap()
* Added untraversed object in izip() structure
* Replaced the pairwise() example with a more general window() example
2003-06-18 19:25:37 +00:00
Raymond Hettinger 7d98fb9806 Add missing DECREF. 2003-06-17 23:14:40 +00:00
Raymond Hettinger bfef18ca0e PyType_GenericAlloc is inherited from object. 2003-05-23 03:55:42 +00:00
Raymond Hettinger d449eab1e4 Fixed dotted name assertion. 2003-05-22 16:32:58 +00:00
Raymond Hettinger 7c2bb5bc57 * Added a substantial number of edge case and argument tests for
the itertoolsmodule.
* Taught itertools.repeat(obj, n) to treat negative repeat counts as
  zero.  This behavior matches that for sequences and prevents
  infinite loops.
2003-05-03 05:59:48 +00:00
Raymond Hettinger 341deb74e7 The previous made the stop argument optional.
It is better to be explicit and just allow stop to be None.
2003-05-02 19:44:20 +00:00
Raymond Hettinger 14ef54cd83 SF bug #730685: itertools.islice stop argument is not optional
* itertools.islice() stop argument did not perform as documented.
* beefed-up test suite
2003-05-02 19:04:37 +00:00
Andrew M. Kuchling dff694bb9d Fix docstring typo 2003-04-14 15:31:27 +00:00
Raymond Hettinger 1da1dbf458 Renamed PyObject_GenericGetIter to PyObject_SelfIter
to more accurately describe what the function does.

Suggested by Thomas Wouters.
2003-03-17 19:46:11 +00:00
Raymond Hettinger 0153826964 Created PyObject_GenericGetIter().
Factors out the common case of returning self.
2003-03-17 08:24:35 +00:00
Raymond Hettinger d1a283be26 Several of the tools can make direct calls the inner iterators. 2003-03-01 01:48:24 +00:00
Raymond Hettinger 61fe64d5de User requested changes to the itertools module.
Subsumed times() into repeat().
Added cycle() and chain().
2003-02-23 04:40:07 +00:00
Guido van Rossum d58f3fce3d Remove unused variable. 2003-02-09 17:19:18 +00:00
Raymond Hettinger 60eca9331a C Code:
* Removed the ifilter flag wart by splitting it into two simpler functions.
* Fixed comment tabbing in C code.
* Factored module start-up code into a loop.

Documentation:
* Re-wrote introduction.
* Addede examples for quantifiers.
* Simplified python equivalent for islice().
* Documented split of ifilter().

Sets.py:
* Replace old ifilter() usage with new.
2003-02-09 06:40:58 +00:00
Raymond Hettinger f0c00241ae * Eliminated tuple re-use in imap(). Doing it correctly made the code
too hard to read.
* Simplified previous changes to izip() to make it easier to read.
2003-02-07 07:26:25 +00:00
Raymond Hettinger 2012f174ea SF bug #681003: itertools issues
* Fixed typo in exception message for times()
* Filled in missing times_traverse()
* Document reasons that imap() did not adopt a None fill-in feature
* Document that count(sys.maxint) will wrap-around on overflow
* Add overflow test to islice()
* Check that starmap()'s argument returns a tuple
* Verify that imap()'s tuple re-use is safe
* Make a similar tuple re-use (with safety check) for izip()
2003-02-07 05:32:58 +00:00
Raymond Hettinger 96ef8115dd Move itertools module from the sandbox and into production. 2003-02-01 00:10:11 +00:00