lucjon / Py-StackExchange

A Python binding for the StackExchange API
http://stackapps.com/questions/198/py-stackexchange-an-api-wrapper-for-python
BSD 3-Clause "New" or "Revised" License
229 stars 76 forks source link

listing badges #44

Open foobarbecue opened 8 years ago

foobarbecue commented 8 years ago

.badges docstring says it returns users, but actually it just seems to return the badge object. Is this the intended behavior?

In [60]: so = stackexchange.Site('stackoverflow')

In [61]: so.badges?
Type:       instancemethod
String Form:<bound method Site.badges of <stackexchange.Site object at 0x7fc1150b3210>>
File:       /home/aaron/sandbox/Py-StackExchange/demo/build/bdist.linux-x86_64/egg/stackexchange/__init__.py
Definition: so.badges(self, ids=None, **kw)
Docstring:  Returns the users with the badges with IDs.

In [62]: so.badges(22)
Out[62]: (<Badge 'Great Question' @ 7fc1150b3d90>)
lucjon commented 8 years ago

Sorry for the late reply, thanks a lot for pointing this out to me. That is indeed a documentation issue, which I've fixed in the latest commit.

While digging into it, however, there were a few other issues with the badge methods which should now be fixed in the latest commit. If you want to get the recipients of a particular badge, you can use the recipients field of the Badge object, e.g. so.badge(22).recipients. Bear in mind this is an 'infinite' generator, so don't try and turn it into a list all at once. For something closer to the documented API endpoint, the Site#badge_recipients method returns a set of Badges as described here.