New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit parameter is confusing #259
Comments
Sigh. Did some more digging. The limit parameter is just passed down to the API level where it really means the chunk size over which the List object iterates. The point of a high-level API is to provide a higher level abstraction, not just expose all the low level details in a slightly different skin. |
For what it's worth, I agree that the parameter name is quite confusing! Wouldn't really mind changing it to Also agree it's not very elegant having to do something like this:
or
just for a common operation like fetching a limited set of results. Thinking about it, one way to make the API a bit more fluent without breaking backwards compatibility, could be to add a new method on the >>> results = site.usercontributions('RoySmith-Mobile').take(5)
>>> print(len(results))
5 The method could look something like this: def take(self, limit):
"""Return a list of up to `limit` results"""
return list(itertools.islice(self, limit)) |
I'm unsure we want to start adding methods like that; we already have the general-purpose itertools library which does all of these sorts of things. But, more than that, returning an iterator is good. We certainly don't want to listify the results. What if you looked at the contributions for [[User:User:Ser Amantio di Nicolao]], with over 3 million edits? I noticed this is called out in a debian release note so I guess I'm not the first person to be bitten by this. |
Absolutely agree that iterators should be the standard. This would just be a convenience method, to use when requesting a small number of results, which I think is quite a common use case. But it would only be a minor convenience over using I see that we already have mentioned |
Looking through the code, I see listing.List already has support for a max_items parameter which looks like it does the right thing. There's also a mysterious "# NOTE: Fix limit" comment. I haven't dug far enough back in the history, but I'm assuming these are related. So, maybe just expose max_items at the Site.usercontributions() level? As much as I argued against duplicating the islice() functionality inside mwclient, there is at least the self-documenting feature. If I was a lazy programmer and didn't read all the documentation before doing anything (yeah, right), at least I would see that the method had both a "max_items" and a "limit" and think to myself, "Oh, that's weird, how do these two differ from each other?", and go digging a bit deeper. And, to be honest
is easier to read than
|
Ooops, sorry, didn't mean to close that. Clicked the wrong button. |
Interesting, I have actually never noticed the |
I've got version 0.10.0. Running this code:
prints:
Expected result: it should print "5". As far as I can tell, the limit parameter is ignored.
The text was updated successfully, but these errors were encountered: