jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Proper deprecation for old DataSite.get_* ......................................................................
[FIX] Proper deprecation for old DataSite.get_*
This removes the explicit deprecation of `_get_propertyitem` and adds a non-deprecated `_get_item` which can be called from `_get_propertyitem`.
So whenever an old `get_*` method (like `get_info`) is called it actually returns a deprecation for that and not for `_get_propertyitem` and `get_item`.
It also avoids using lambda by replacing it with functools.
Change-Id: I71e8eb4e7df3f2ec7ad9aad39d10be88ace4ed42 --- M pywikibot/site.py M tests/wikibase_tests.py 2 files changed, 20 insertions(+), 19 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index c6381b5..20cc693 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -18,6 +18,7 @@ import datetime import hashlib import itertools +import functools import os import re import sys @@ -6625,20 +6626,21 @@ props = attr.replace("get_", "") if props in ['info', 'sitelinks', 'aliases', 'labels', 'descriptions', 'urls']: + issue_deprecation_warning('DataSite.{0}()'.format(attr), + 'WikibasePage', 2) if props == 'urls': props = 'sitelinks/urls' method = self._get_propertyitem - f = lambda *args, **params: \ - method(props, *args, **params) + f = functools.partial(method, props) if hasattr(method, "__doc__"): f.__doc__ = method.__doc__ return f + return super(APISite, self).__getattr__(attr)
- @deprecated("pywikibot.PropertyPage") def _get_propertyitem(self, props, source, **params): """Generic method to get the data for multiple Wikibase items.""" - wbdata = self.get_item(source, props=props, **params) + wbdata = self._get_item(source, props=props, **params) if props == 'info': return wbdata
@@ -6652,6 +6654,14 @@ @deprecated("pywikibot.WikibasePage") def get_item(self, source, **params): """Get the data for multiple Wikibase items.""" + return self._get_item(source, **params) + + # Only separated from get_item to avoid the deprecation message via + # _get_propertyitem + def _get_item(self, source, **params): + assert set(params) <= set(['props']), \ + 'Only "props" is a valid kwarg, not {0}'.format(set(params) - + set(['props'])) if isinstance(source, int) or \ isinstance(source, basestring) and source.isdigit(): ids = 'q' + str(source) diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index e49945c..e2cc4f9 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -1044,56 +1044,47 @@ """Test deprecated DataSite get_* methods."""
cached = True - # These methods are implemented using __getattr__, - # so the filename will be detected as site.py, - # requiring _do_test_warning_filename = False
def test_get_info(self): """Test get_info.""" - self._do_test_warning_filename = False data = self.repo.get_info(60) - self.assertDeprecation() + self.assertOneDeprecation() self.assertIsInstance(data, dict) self.assertIn('title', data) self.assertEqual(data['title'], 'Q60')
def test_get_labels(self): """Test get_labels.""" - self._do_test_warning_filename = False data = self.repo.get_labels(60) - self.assertDeprecation() + self.assertOneDeprecation() self.assertIsInstance(data, dict) self.assertIn('en', data)
def test_get_aliases(self): """Test get_aliases.""" - self._do_test_warning_filename = False data = self.repo.get_aliases(60) - self.assertDeprecation() + self.assertOneDeprecation() self.assertIsInstance(data, dict) self.assertIn('en', data)
def test_get_descriptions(self): """Test get_descriptions.""" - self._do_test_warning_filename = False data = self.repo.get_descriptions(60) - self.assertDeprecation() + self.assertOneDeprecation() self.assertIsInstance(data, dict) self.assertIn('en', data)
def test_get_sitelinks(self): """Test get_sitelinks.""" - self._do_test_warning_filename = False data = self.repo.get_sitelinks(60) - self.assertDeprecation() + self.assertOneDeprecation() self.assertIsInstance(data, dict) self.assertIn('enwiki', data)
def test_get_urls(self): """Test get_urls.""" - self._do_test_warning_filename = False data = self.repo.get_urls(60) - self.assertDeprecation() + self.assertOneDeprecation() self.assertIsInstance(data, dict) self.assertIn('enwiki', data)
pywikibot-commits@lists.wikimedia.org