jenkins-bot submitted this change.

View Change


Approvals: jenkins-bot: Verified JJMC89: Looks good to me, approved
[cleanup] Drop pywikibot.BaseSite and pywikibotAPISite

BaseSite and APISite are used for typing and interface check in Site()
constructor function. They were introduced with b903d0aa for typing
and b17ca6e8 for interface check. Other BaseSite subclasses like
DataSite and ClosedSite were already removed in an earlier version.

They were never intended for direct usage and it should never be used
directly. Therefore is not part of pywikibot.__all__ list. See also the
warning at
https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.html#pywikibot.Site

To be safe, remove direct imports of BaseSite and APISite in
pywikibot.__init__.py

Bug: T355915
Change-Id: I3de35e9780a1184cbb9492f2c9ab5b91c523805a
---
M pywikibot/__init__.py
M pywikibot/page/_wikibase.py
M scripts/redirect.py
M scripts/speedy_delete.py
M tests/category_bot_tests.py
5 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 22002d8..4fc3a17 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -1,6 +1,6 @@
"""The initialization file for the Pywikibot framework."""
#
-# (C) Pywikibot team, 2008-2023
+# (C) Pywikibot team, 2008-2024
#
# Distributed under the terms of the MIT license.
#
@@ -14,7 +14,7 @@
from contextlib import suppress
from queue import Queue
from time import sleep as time_sleep
-from typing import Any, cast
+from typing import Any, TYPE_CHECKING, cast
from urllib.parse import urlparse
from warnings import warn

@@ -67,11 +67,15 @@
stdout,
warning,
)
-from pywikibot.site import APISite, BaseSite
+from pywikibot.site import BaseSite as _BaseSite
from pywikibot.time import Timestamp
from pywikibot.tools import normalize_username


+if TYPE_CHECKING:
+ from pywikibot.site import APISite
+
+
__all__ = (
'__copyright__', '__description__', '__download_url__', '__license__',
'__maintainer__', '__maintainer_email__', '__name__', '__url__',
@@ -127,11 +131,11 @@
return matched_sites[0]


-def Site(code: str | None = None, # noqa: 134
+def Site(code: str | None = None, # noqa: N802
fam: str | Family | None = None,
user: str | None = None, *,
- interface: str | BaseSite | None = None,
- url: str | None = None) -> BaseSite:
+ interface: str | _BaseSite | None = None,
+ url: str | None = None) -> _BaseSite:
"""A factory method to obtain a Site object.

Site objects are cached and reused by this method.
@@ -242,7 +246,7 @@
else:
interface = getattr(tmp, interface)

- if not issubclass(interface, BaseSite):
+ if not issubclass(interface, _BaseSite):
warning(f'Site called with interface={interface.__name__}')

user = normalize_username(user)
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 34607ce..b5de1b3 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -9,7 +9,7 @@
* WikibaseEntity: base interface for Wikibase entities.
"""
#
-# (C) Pywikibot team, 2013-2023
+# (C) Pywikibot team, 2013-2024
#
# Distributed under the terms of the MIT license.
#
@@ -65,7 +65,7 @@
)

if TYPE_CHECKING:
- LANGUAGE_IDENTIFIER = str | pywikibot.APISite
+ LANGUAGE_IDENTIFIER = str | pywikibot.site.APISite
ALIASES_TYPE = dict[LANGUAGE_IDENTIFIER, list[str]]
LANGUAGE_TYPE = dict[LANGUAGE_IDENTIFIER, str]
SITELINK_TYPE = (
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 3a31af2..bffa83c 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -66,7 +66,7 @@
&params;
"""
#
-# (C) Pywikibot team, 2004-2023
+# (C) Pywikibot team, 2004-2024
#
# Distributed under the terms of the MIT license.
#
@@ -408,11 +408,12 @@
else:
raise NotImplementedError(f'No valid action "{action}" found.')

- def get_sd_template(self, site=None) -> str | None:
+ def get_sd_template(
+ self, site: pywikibot.site.BaseSite | None = None
+ ) -> str | None:
"""Look for speedy deletion template and return it.

:param site: site for which the template has to be given
- :type site: pywikibot.BaseSite
:return: A valid speedy deletion template.
"""
title = None
diff --git a/scripts/speedy_delete.py b/scripts/speedy_delete.py
index 76dab20..0f4d0c3 100755
--- a/scripts/speedy_delete.py
+++ b/scripts/speedy_delete.py
@@ -22,7 +22,7 @@
.. note:: This script currently only works for the Wikipedia project.
"""
#
-# (C) Pywikibot team, 2007-2023
+# (C) Pywikibot team, 2007-2024
#
# Distributed under the terms of the MIT license.
#
@@ -325,7 +325,7 @@
def __init__(self, **kwargs) -> None:
"""Initializer.

- :keyword pywikibot.APISite site: the site to work on
+ :keyword pywikibot.site.APISite site: the site to work on
"""
super().__init__(**kwargs)
csd_cat = i18n.translate(self.site, self.csd_cat_title)
diff --git a/tests/category_bot_tests.py b/tests/category_bot_tests.py
index 8122c32..e96cec3 100755
--- a/tests/category_bot_tests.py
+++ b/tests/category_bot_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""Tests for the category bot script."""
#
-# (C) Pywikibot team, 2015-2022
+# (C) Pywikibot team, 2015-2024
#
# Distributed under the terms of the MIT license.
#
@@ -12,7 +12,7 @@
from unittest.mock import Mock, patch

import pywikibot
-from pywikibot import BaseSite
+from pywikibot.site import BaseSite
from scripts.category import CategoryMoveRobot, CategoryPreprocess
from tests.aspects import DefaultSiteTestCase, TestCase


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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3de35e9780a1184cbb9492f2c9ab5b91c523805a
Gerrit-Change-Number: 994187
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <dalangi-ctr@wikimedia.org>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged