[Pyrex] Question, plus suggestions for improvement?

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Aug 2 04:06:58 UTC 2006


Bill Mill wrote:

> I thought, on inspection, that x, y, and z would need to be declared
> as objects to accept arbitrary values from a list. However, if I pass
> in a list of strings or floats, everything works just fine.

I'm betting you never tested it with a list of
more than 3 items.

You seem to have some special case code in there
for dealing with the first 3 items, which doesn't
use the x, y, z variables.

With a list of length 4, an exception occurs as
expected:

['a', 'b', 'c', 'd']
['a', 'b', 'd', 'c']
['a', 'c', 'b', 'd']
['a', 'c', 'd', 'b']
['a', 'd', 'b', 'c']
['a', 'd', 'c', 'b']
Traceback (most recent call last):
   File "test.py", line 6, in ?
     for p in Permute2(["a","b","c","d"]):
   File "perm.pyx", line 32, in perm.Permute2.__next__
     y = self.lst[j]
TypeError: an integer is required

The moral: Make sure your tests cover all the code
paths!

--
Greg



More information about the Pyrex mailing list