jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655709 )
Change subject: [cleanup] Deprecate loadimageinfo return statement
......................................................................
[cleanup] Deprecate loadimageinfo return statement
Change-Id: I626d3b15473d2b3fab8de0ff2cae98d16b5974f9
---
M pywikibot/site/__init__.py
M tests/site_tests.py
2 files changed, 34 insertions(+), 4 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 348f34d..cb059ef 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
"""
Objects representing MediaWiki sites (wikis).
@@ -6,16 +5,18 @@
groups of wikis on the same topic in different languages.
"""
#
-# (C) Pywikibot team, 2008-2020
+# (C) Pywikibot team, 2008-2021
#
# Distributed under the terms of the MIT license.
#
import datetime
import functools
import heapq
+import inspect
import itertools
import json
import mimetypes
+import opcode
import os
import re
import time
@@ -1314,6 +1315,23 @@
page,
'loadimageinfo: Query on %s returned no imageinfo')
+ # inspect whether the result is assigned and print an deprecation
+ # warning in that case; implementation inspired by
+ #
https://stackoverflow.com/questions/813882/is-there-a-way-to-check-whether-…
+ try:
+ frame = inspect.currentframe().f_back
+ next_opcode = opcode.opname[
+ frame.f_code.co_code[frame.f_lasti + 3]]
+ if next_opcode in ('POP_TOP', 'ROT_TWO',
'ROT_THREE'):
+ issue_deprecation_warning(
+ 'APISite.loadimageinfo() result dict and any assignment',
+ "pageitem['imageinfo'] if history is True "
+ "else pageitem['imageinfo'][0]",
+ warning_class=FutureWarning,
+ since='20210110')
+ finally:
+ del frame
+
return (pageitem['imageinfo']
if history else pageitem['imageinfo'][0])
diff --git a/tests/site_tests.py b/tests/site_tests.py
index e3469e5..9a00492 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1,7 +1,6 @@
-# -*- coding: utf-8 -*-
"""Tests for the site module."""
#
-# (C) Pywikibot team, 2008-2020
+# (C) Pywikibot team, 2008-2021
#
# Distributed under the terms of the MIT license.
#
@@ -108,6 +107,19 @@
self.assertEqual(self.site.category_namespaces(),
list(self.site.namespace(14, all=True)))
+ def test_loadimageinfo(self):
+ """Test deprecation warning if result of loadimageinfo() is
used."""
+ file = pywikibot.FilePage(self.site, 'foo.jpg')
+ if not file.file_is_shared():
+ self.skipPage('test file is not shared from image repository.')
+ self.site.loadimageinfo(file)
+ self.assertNoDeprecation()
+ result = self.site.loadimageinfo(file) # noqa: F841
+ self.assertOneDeprecation()
+ x = []
+ x.append(self.site.loadimageinfo(file))
+ self.assertOneDeprecation()
+
class TestSiteDryDeprecatedFunctions(DefaultDrySiteTestCase,
DeprecationTestCase):
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655709
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I626d3b15473d2b3fab8de0ff2cae98d16b5974f9
Gerrit-Change-Number: 655709
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged