jenkins-bot merged this change.

View Change

Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
[cleanup] Cleanup getFilesFromAnHash and getImagesFromAnHash

- Make hash_found parameter mandatory for both methods.
As noted in _get_titles_with_hash helper function it
does not make any sense to call these methods with no
parameter. Instead of the warning a TypeError is raised.
- Remove helper function and call allimages method directly.
- Call getFilesFromAnHash from older getImagesFromAnHash.
- Throw a FutureWarning with this method that they can be
desupported and removed soon after more than 5 years of
deprecation.

Bug: T106121
Change-Id: I920e6c6f71c9d842be9496d8eeca0c3810dae966
---
M pywikibot/site/__init__.py
1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 5ee61be..f7b20ab 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -6267,35 +6267,26 @@
"""Backwards-compatible interface to exturlusage()."""
return self.exturlusage(siteurl, total=limit, protocol=euprotocol)

- def _get_titles_with_hash(self, hash_found=None):
- """Helper for the deprecated method get(Files|Images)FromAnHash."""
- # This should be removed with together with get(Files|Images)FromHash
- if hash_found is None:
- # This makes absolutely NO sense.
- pywikibot.warning(
- 'The "hash_found" parameter in "getFilesFromAnHash" and '
- '"getImagesFromAnHash" are not optional.')
- return
- return [image.title(with_ns=False)
- for image in self.allimages(sha1=hash_found)]
-
- @deprecated('Site().allimages', since='20141219')
- def getFilesFromAnHash(self, hash_found=None):
+ @deprecated('Site().allimages(sha1=hash_found)', since='20141219',
+ future_warning=True)
+ def getFilesFromAnHash(self, hash_found):
"""
Return all files that have the same hash.

DEPRECATED: Use L{APISite.allimages} instead using 'sha1'.
"""
- return self._get_titles_with_hash(hash_found)
+ return [image.title(with_ns=False)
+ for image in self.allimages(sha1=hash_found)]

- @deprecated('Site().allimages', since='20141219')
- def getImagesFromAnHash(self, hash_found=None):
+ @deprecated('Site().allimages(sha1=hash_found)', since='20141219',
+ future_warning=True)
+ def getImagesFromAnHash(self, hash_found):
"""
Return all images that have the same hash.

DEPRECATED: Use L{APISite.allimages} instead using 'sha1'.
"""
- return self._get_titles_with_hash(hash_found)
+ return self.getFilesFromAnHash(hash_found)

@need_right('edit')
def is_uploaddisabled(self):

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I920e6c6f71c9d842be9496d8eeca0c3810dae966
Gerrit-Change-Number: 606438
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)