hudora/pyShipping — pull request #2 by Lacrymology (2012-07-17 20:10:00+00:00)
Title: Bug when layer cannot be filled

I'm seeing a bug when the `packlayer` and `packbin` functions hit lines `84` abd `109` respectively.

The bug seems to be that since both those functions and the underlying `packstrip` modify the in-argument `packages`, when the fail reason is that no layer could be created, an empty list is returned instead of `rest` (because the `packages = rest` line is omitted from code)

Here's some code to reproduce the bug:

>>> from pyshipping import package, binpack_simple

>>> packages = [package.Package("80x30x20"), package.Package("120x30x20"), package.Package("120x30x20")]

>>> bin = package.Package("100x50x50")

>>> binpack_simple.binpack(packages, bin)
([[]], [])

see how the `rest` return value is empty instead of having the two packages too big to pack.

I don't completely understand in what circumstances the code breaks on those lines, and when does it break the other way (working properly), so I'm not certain my solution is the best approach, but it seems to work.