jenkins-bot submitted this change.

View Change

Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
[bugfix] Solve circular import if user-config.p is missing

- Do not import or assign unused exceptions; ModuleDeprecationWrapper
will provide the requested module part
- import pywikibot.exceptions as exceptions to solve circular import

Bug: T281551
Change-Id: I892d8c40496c3a8e7b2f065726b60e98964e64d3
---
M pywikibot/__init__.py
M pywikibot/data/api.py
M pywikibot/i18n.py
3 files changed, 18 insertions(+), 69 deletions(-)

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 7ec3875..15b0b0d 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -18,7 +18,7 @@
from urllib.parse import urlparse
from warnings import warn

-import pywikibot.exceptions
+import pywikibot.exceptions as exceptions
from pywikibot import config as _config
from pywikibot.__metadata__ import (
__copyright__,
@@ -46,6 +46,10 @@
ui,
)
from pywikibot.diff import PatchManager
+from pywikibot.exceptions import (
+ CoordinateGlobeUnknownError,
+ DEPRECATED_EXCEPTIONS,
+)
from pywikibot.family import AutoFamily, Family
from pywikibot.i18n import translate
from pywikibot.logging import (
@@ -62,55 +66,11 @@
from pywikibot.tools import (
ModuleDeprecationWrapper as _ModuleDeprecationWrapper,
)
-from pywikibot.tools import classproperty
+from pywikibot.tools import classproperty, normalize_username
from pywikibot.tools import deprecate_arg as _deprecate_arg
-from pywikibot.tools import normalize_username, suppress_warnings
from pywikibot.tools.formatter import color_format


-with suppress_warnings(category=FutureWarning):
- from pywikibot.data.api import UploadWarning
- from pywikibot.exceptions import (
- DEPRECATED_EXCEPTIONS,
- CaptchaError,
- CascadeLockedPage,
- CircularRedirect,
- CoordinateGlobeUnknownError,
- CoordinateGlobeUnknownException,
- EditConflict,
- Error,
- FatalServerError,
- InterwikiRedirectPage,
- InvalidTitle,
- IsNotRedirectPage,
- IsRedirectPage,
- LockedNoPage,
- LockedPage,
- NoCreateError,
- NoMoveTarget,
- NoPage,
- NoUsername,
- NoWikibaseEntity,
- OtherPageSaveError,
- PageCreatedConflict,
- PageDeletedConflict,
- PageRelatedError,
- PageSaveRelatedError,
- SectionError,
- Server414Error,
- Server504Error,
- ServerError,
- SiteDefinitionError,
- SpamblacklistError,
- TitleblacklistError,
- UnknownExtension,
- UnknownFamily,
- UnknownSite,
- UnsupportedPage,
- WikiBaseError,
- )
-
-
__all__ = (
'__copyright__', '__description__', '__download_url__', '__license__',
'__maintainer__', '__maintainer_email__', '__name__',
@@ -1366,7 +1326,7 @@
# we can drop them from both our import and __all__ listing.

EXCEPTION_CLASSES = {
- n for n, _ in inspect.getmembers(pywikibot.exceptions, inspect.isclass)
+ n for n, _ in inspect.getmembers(exceptions, inspect.isclass)
}

EXCEPTION_CLASSES.add('UploadWarning')
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index d487ac5..2d9c6b1 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -12,6 +12,7 @@
import pprint
import re
import traceback
+
from collections.abc import Container, MutableMapping, Sized
from contextlib import suppress
from email.generator import BytesGenerator
@@ -24,7 +25,7 @@
from warnings import warn

import pywikibot
-import pywikibot.exceptions
+
from pywikibot import config, login
from pywikibot.backports import Tuple, removeprefix
from pywikibot.comms import http
@@ -3155,23 +3156,13 @@
page._lintinfo.pop('ns')


-APIError = pywikibot.exceptions.APIError
-UploadWarning = pywikibot.exceptions.UploadError
-APIMWException = pywikibot.exceptions.APIMWError
-
wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr(
- 'APIError',
- replacement_name='pywikibot.exceptions.APIError',
- since='20210423',
- future_warning=True)
+ 'APIError', replacement_name='pywikibot.exceptions.APIError',
+ since='20210423', future_warning=True)
wrapper._add_deprecated_attr(
- 'UploadWarning',
- replacement_name='pywikibot.exceptions.UploadError',
- since='20210423',
- future_warning=True)
+ 'UploadWarning', replacement_name='pywikibot.exceptions.UploadError',
+ since='20210423', future_warning=True)
wrapper._add_deprecated_attr(
- 'APIMWException',
- replacement_name='pywikibot.exceptions.APIMWError',
- since='20210423',
- future_warning=True)
+ 'APIMWException', replacement_name='pywikibot.exceptions.APIMWError',
+ since='20210423', future_warning=True)
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 39f424e..bd83e13 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -23,6 +23,7 @@
import os
import pkgutil
import re
+
from collections import defaultdict
from collections.abc import Mapping
from contextlib import suppress
@@ -31,7 +32,7 @@
from warnings import warn

import pywikibot
-import pywikibot.exceptions
+
from pywikibot import __url__, config
from pywikibot.backports import List, cache
from pywikibot.plural import plural_rule
@@ -861,11 +862,8 @@
return pywikibot.input(prompt, password)


-TranslationError = pywikibot.exceptions.TranslationError
-
wrapper = ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr(
'TranslationError',
replacement_name='pywikibot.exceptions.TranslationError',
- since='20210423',
- future_warning=True)
+ since='20210423', future_warning=True)

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I892d8c40496c3a8e7b2f065726b60e98964e64d3
Gerrit-Change-Number: 684014
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Isaacandy <isaac@iznd.xyz>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: Siebrand <siebrand@kitano.nl>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-MessageType: merged