jenkins-bot submitted this change.

View Change

Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
[IMPR] Allow multiple types of contributors parameter given for revision_count()

- Currently contributors parameter of Page.revision_count() is either
None or an iterable of username string. Now a single pywikibot.User
or an iterable of pywikibot.User may be given as well as a single
string as username.
- Some tests added
- Show a FutureWarning with contributingUsers because the result is
not as described and the method is deprecated for 5 years already

Change-Id: If7ef18690a9ab42c76cb22e28676fd2aaf8136a2
---
M pywikibot/page/__init__.py
M tests/page_tests.py
2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index a286f29..bed8745 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -1834,7 +1834,7 @@
self.revisions(total=total,
starttime=starttime, endtime=endtime))

- @deprecated('contributors()', since='20150206')
+ @deprecated('contributors().keys()', since='20150206', future_warning=True)
@deprecated_args(step=True)
def contributingUsers(self, total=None):
"""
@@ -1842,25 +1842,31 @@

@param total: iterate no more than this number of revisions in total

- @rtype: set
+ @rtype: dict_keys
"""
return self.contributors(total=total).keys()

- def revision_count(self, contributors=None):
- """
- Determine number of edits from a set of contributors.
+ def revision_count(self, contributors=None) -> int:
+ """Determine number of edits from contributors.

@param contributors: contributor usernames
- @type contributors: iterable of str
-
+ @type contributors: iterable of str or pywikibot.User,
+ a single pywikibot.User, a str or None
@return: number of edits for all provided usernames
- @rtype: int
"""
- if not contributors:
- return len(list(self.revisions()))
-
cnt = self.contributors()
- return sum(cnt[username] for username in contributors)
+
+ if not contributors:
+ return sum(cnt.values())
+
+ if isinstance(contributors, User):
+ contributors = contributors.username
+
+ if isinstance(contributors, str):
+ return cnt[contributors]
+
+ return sum(cnt[user.username] if isinstance(user, User) else cnt[user]
+ for user in contributors)

@deprecated('oldest_revision', since='20140421', future_warning=True)
def getCreator(self):
diff --git a/tests/page_tests.py b/tests/page_tests.py
index e10dc23..c1b3900 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -932,6 +932,12 @@
cnt = mp.contributors()
self.assertEqual(rev_count, sum(cnt.values()))

+ user, count = cnt.most_common(1)[0]
+ self.assertEqual(mp.revision_count([user]), count)
+ self.assertEqual(mp.revision_count(user), count)
+ self.assertEqual(mp.revision_count(pywikibot.User(self.site, user)),
+ count)
+
top_two = cnt.most_common(2)
self.assertIsInstance(top_two, list)
self.assertLength(top_two, 2)

To view, visit change 621881. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If7ef18690a9ab42c76cb22e28676fd2aaf8136a2
Gerrit-Change-Number: 621881
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged