jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
Revert "[cleanup] Deprecate loadimageinfo return statement"

Python 6.0.6 may be a breaking change and this new behaviour
is already announced. The deprecation warning does not work
for Python 3.5.

This reverts commit 0010abde8dfd37cd8d2bdead4dffa072cf378f8f.

Change-Id: Id629c8485631789ca5f931e00998e4094ef21508
---
M pywikibot/site/__init__.py
M tests/site_tests.py
2 files changed, 1 insertion(+), 35 deletions(-)

diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 941fbd5..893218b 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -12,11 +12,9 @@
import datetime
import functools
import heapq
-import inspect
import itertools
import json
import mimetypes
-import opcode
import os
import re
import time
@@ -1329,23 +1327,6 @@
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-function-output-is-assigned-to-a-variable-in-pyt
- 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 b6b4d1a..1b37e0d 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -18,7 +18,7 @@
from pywikibot import config
from pywikibot.data import api
from pywikibot.exceptions import HiddenKeyError
-from pywikibot.tools import PYTHON_VERSION, suppress_warnings
+from pywikibot.tools import suppress_warnings

from tests import patch, unittest_print
from tests.aspects import (
@@ -33,7 +33,6 @@
WikidataTestCase,
)
from tests.basepage import BasePageLoadRevisionsCachingTestBase
-from tests.utils import expected_failure_if


class TestSiteObjectDeprecatedFunctions(DefaultSiteTestCase,
@@ -108,20 +107,6 @@
self.assertEqual(self.site.category_namespaces(),
list(self.site.namespace(14, all=True)))

- @expected_failure_if(PYTHON_VERSION < (3, 6))
- 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.skipTest('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 change 658042. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Id629c8485631789ca5f931e00998e4094ef21508
Gerrit-Change-Number: 658042
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged