jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup] Deprecate SelfCall classes

These SelfCall classes were added in commit ce164aa so "site.namespaces()"
aliases to "site.namespaces". It doesn't explain why this desirable and
detracts from PEP20's 'there should be one way to do it' axiom.

SelfCall is used by BaseSite's sitename property and NamespacesDict.
NamespacesDict already deprecated its usage in 2015. Once referencing
them as functions is gone we can remove the SelfCall classes.

Bug: T281200
Change-Id: I17f5b16d3be899768bd576336478f790f4f7b4cd
---
M pywikibot/site/_namespace.py
M pywikibot/tools/__init__.py
M tests/basesite_tests.py
M tests/site_tests.py
4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/pywikibot/site/_namespace.py b/pywikibot/site/_namespace.py
index 8edcf5f..540ac6b 100644
--- a/pywikibot/site/_namespace.py
+++ b/pywikibot/site/_namespace.py
@@ -305,8 +305,6 @@
APISite was callable.
"""

- _own_desc = 'the namespaces property'
-
def __init__(self, namespaces):
"""Create new dict using the given namespaces."""
super().__init__()
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 13b7bff..3538673 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -1035,11 +1035,11 @@

def __call__(self):
"""Do nothing and just return itself."""
- if hasattr(self, '_own_desc'):
- issue_deprecation_warning('Calling {}'.format(self._own_desc),
- 'it directly',
- warning_class=FutureWarning,
- since='20150515')
+ issue_deprecation_warning('Referencing this attribute like a function',
+ 'it directly',
+ warning_class=FutureWarning,
+ since='20210420')
+
return self


diff --git a/tests/basesite_tests.py b/tests/basesite_tests.py
index 559020b..31a2245 100644
--- a/tests/basesite_tests.py
+++ b/tests/basesite_tests.py
@@ -8,8 +8,13 @@

import pywikibot

+from pywikibot.tools import suppress_warnings
+
from tests.aspects import DefaultSiteTestCase, TestCase, unittest

+WARN_SELF_CALL = (r'Referencing this attribute like a function '
+ r'is deprecated for .*; use it directly instead')
+

class TestBaseSiteProperties(TestCase):

@@ -81,9 +86,15 @@
self.assertIsInstance(mysite.lang, str)
self.assertEqual(mysite, pywikibot.Site(self.code, self.family))
self.assertIsInstance(mysite.user(), (str, type(None)))
- self.assertEqual(mysite.sitename(), '%s:%s' % (self.family, code))
+ self.assertEqual(mysite.sitename, '%s:%s' % (self.family, code))
self.assertIsInstance(mysite.linktrail(), str)
self.assertIsInstance(mysite.redirect(), str)
+
+ # sitename attribute could also be referenced like a function
+
+ with suppress_warnings(WARN_SELF_CALL, category=FutureWarning):
+ self.assertEqual(mysite.sitename(), '%s:%s' % (self.family, code))
+
try:
dabcat = mysite.disambcategory()
except pywikibot.Error as e:
diff --git a/tests/site_tests.py b/tests/site_tests.py
index b3362b5..971937e 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -100,8 +100,9 @@
"""Test that namespaces is callable and returns itself."""
site = self.get_site()
self.assertIs(site.namespaces(), site.namespaces)
- self.assertOneDeprecationParts('Calling the namespaces property',
- 'it directly')
+ self.assertOneDeprecationParts(
+ 'Referencing this attribute like a function',
+ 'it directly')


class TestSiteObject(DefaultSiteTestCase):

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I17f5b16d3be899768bd576336478f790f4f7b4cd
Gerrit-Change-Number: 681502
Gerrit-PatchSet: 3
Gerrit-Owner: Damian <atagar1@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged