Pull requests

#80 Declined
Repository
cbjadwani cbjadwani
Branch
default
Repository
pypy pypy
Branch
default

Fix lib_pypy/itertools.py

Author
  1. cbjadwani
Reviewers
Description

Fix bugs and add missing classes in the pure python itertools in lib_pypy directory. Passes all tests in "lib-python/2.7/test/test_itertools.py"

Comments (8)

  1. Amaury Forgeot d'Arc

    Some remarks: - check_number(): this is not the right way; it will return True for lists and tuples! I realize interp_itertools.py is wrong as well. In C PyNumber_Check() tests for the presence of int or float. - "CPython raises a TypeError when next() is not defined": you could use the built-in next() function, instead of the method call. - compress() is missing a docstring.

    1. cbjadwani author

      Fixed:

      • Fixed check_number, now checks for presence of __int__ or __float__
      • Use next(iter) instead iter.next()
      • Added doc string for compress

      Other changes:

      • cycle: Now using a 'saving iterator' for first iteration, removed the must_save state.
      • imap: Now assigning a default func in __init__ instead of handling it in next()
      • product: Fixed kwargs error check
      • takewhile: Fix, was not checking for end of iteration, so next() was still iterating after raising StopIteration
      • tee: Copy contruction was adding tees of self incorrectly.
  2. Alex Gaynor

    Can you please make any methods/attributes that aren't part of the public Python API have a leading underscore. I saw a few examples of those looking through here.

    1. cbjadwani author

      Fixed.

      Also, added tests for cases that were not caught by existing tests. Fixed iterp_itertools.check_number as per Amaury's remark above.

  3. cbjadwani author

    Copying CPython's itertools.tee I have updated tee to use a linked list for shared data (_TeeData.next_link). But I am not sure about the LINKCELLS value. What would be the optimal value for pypy?

  4. Armin Rigo

    Note that lib_pypy/itertools.py is, as the comment at the top says, not used at all by normal pypy's. I will accept this pull request, but then immediately kill lib_pypy/itertools.py as not really useful to have around and maintain.

  5. Armin Rigo

    cbjadwani: sorry to basically kill your work by removing itertools.py. If you want to optimize pypy/module/itertools instead, you are welcome: we did not spend much efforts e.g. making the tee lists as efficient as CPython's.