Danek Duvall wrote:
On Thu, Feb 19, 2009 at 07:52:43PM -0800, johan...@sun.com wrote:
The problem is that this code doesn't treat the thing it calls a list as
an iterable. It calls list(fmri_list) on the object and then proceeds
to treat it as a list. You don't call list() on an actual list;
Well, you can, and it would have exactly the same behavior, but I see your
point -- it expects a generator, or otherwise it wouldn't need to cache the
contents so that it can re-iterate.
Does it ever take anything but a generator, or other unsized iterator? If
it weren't for the progress tracking, the loop could be written as
It used to take a list, but when I removed the manifest paths, it seemed
more reasonable to pass in the generator from gen_installed_pkgs, then
force the caller to do the list conversion. If python had interfaces,
the argument would be forced to implement essentially "iterable" and
"countable", beyond that, it doesn't really care. That said, I settled
on calling it fmris, and doing fmris = list(fmris). From what I can
tell, that's acceptable to everyone.
for idx, elem in enumerate(fmri_list):
if stopping_early:
break
added_fmri = elem
...
and you could catch a TypeError when calling len(fmri_list) in the progress
tracker start, allowing for a sized iterator to give you percentage progress,
and an unsized iterator such as a generator to simply give you a spinner.
Or, if you know the length of the generator, you could pass that in, too.
I'm inclined to leave things as is and fix this later if we decide we
absolutely need this behavior. I've updated the docstring as suggested
below.
Brock
At any rate, from the point of view of the consumer of the method, you can
pass in any iterable you want, and that's who would care about the name of
the argument. So I'd probably just call it "fmris", and the method
_process_fmris(). The method itself can handle its input however is most
appropriate.
But given how deep in the guts this thing is, I don't really care too much.
Regardless, it'd be good to update the docstring to remove the specific
mention of "list".
Danek
_______________________________________________
pkg-discuss mailing list
pkg-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
_______________________________________________
pkg-discuss mailing list
pkg-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss