jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1103898?usp=email )
Change subject: fix: remove unintentional pywikibot.warn() ...................................................................... fix: remove unintentional pywikibot.warn() - replace pywikibot.warn() with warnings.warn() - replace pywikibot.warn() with pywikibot.warning() in PropertyGenerator - remove warning in ReplaceRobot.apply_replacements because this deprecation message is 10 years old. Change-Id: Ia6057f3126f33ef8430bb57b76d6653e9fe69e9b --- M pywikibot/__init__.py M pywikibot/bot.py M pywikibot/data/api/_generators.py M pywikibot/family.py M pywikibot/login.py M scripts/replace.py 6 files changed, 17 insertions(+), 24 deletions(-) Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index 2375309..207eff1 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -11,12 +11,12 @@ import re import sys import threading +import warnings from contextlib import suppress from queue import Queue from time import sleep as time_sleep from typing import TYPE_CHECKING, Any, cast from urllib.parse import urlparse -from warnings import warn from pywikibot import config as _config from pywikibot import exceptions @@ -244,8 +244,8 @@ debug(f"Instantiated {interface.__name__} object '{_sites[key]}'") if _sites[key].code != code: - warn(f'Site {_sites[key]} instantiated using different code ' - f'"{code}"', UserWarning, 2) + warnings.warn(f'Site {_sites[key]} instantiated using different ' + f'code "{code}"', UserWarning, 2) return _sites[key] diff --git a/pywikibot/bot.py b/pywikibot/bot.py index e3a7b62..ff6d1cf 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -128,7 +128,6 @@ from pathlib import Path from textwrap import fill from typing import TYPE_CHECKING, Any -from warnings import warn import pywikibot import pywikibot.logging as pwb_logging @@ -730,8 +729,8 @@ :return: list of arguments not recognised globally """ if pywikibot._sites: - warn('Site objects have been created before arguments were handled', - UserWarning) + warnings.warn('Site objects have been created before arguments were ' + 'handled', UserWarning) # get commandline arguments if necessary if not args: @@ -1152,8 +1151,8 @@ """ if 'generator' in kwargs: if hasattr(self, 'generator'): - pywikibot.warn(f'{type(self).__name__} has a generator' - ' already. Ignoring argument.') + warnings.warn(f'{type(self).__name__} has a generator' + ' already. Ignoring argument.') else: self.generator: Iterable = kwargs.pop('generator') diff --git a/pywikibot/data/api/_generators.py b/pywikibot/data/api/_generators.py index f48459d..ac1c981 100644 --- a/pywikibot/data/api/_generators.py +++ b/pywikibot/data/api/_generators.py @@ -805,8 +805,8 @@ if d is not data_dict: self._update_old_result_dict(d, data_dict) else: - pywikibot.warn('Skipping result without title: ' - + str(data_dict)) + pywikibot.warning('Skipping result without title: ' + + str(data_dict)) def _fully_retrieved_data_dicts(self, resultdata): """Yield items of self._previous_dicts that are not in resultdata.""" diff --git a/pywikibot/family.py b/pywikibot/family.py index f72b4db..70d1934 100644 --- a/pywikibot/family.py +++ b/pywikibot/family.py @@ -567,7 +567,8 @@ """Return interface to use for code.""" if code in self.interwiki_removals: if code in self.codes: - pywikibot.warn(f'Interwiki removal {code} is in {self} codes') + warnings.warn(f'Interwiki removal {code} is in {self} codes', + FamilyMaintenanceWarning, stacklevel=2) if code in self.closed_wikis: return 'ClosedSite' if code in self.removed_wikis: diff --git a/pywikibot/login.py b/pywikibot/login.py index b670c59..5760c3a 100644 --- a/pywikibot/login.py +++ b/pywikibot/login.py @@ -536,10 +536,11 @@ assert password is not None and user is not None super().__init__(password=None, site=site, user=None) if self.password: - pywikibot.warn( + warn( f'Password exists in password file for {self.site}: ' f'{self.username}. Password is unnecessary and should be' - ' removed if OAuth enabled.' + ' removed if OAuth enabled.', + _PasswordFileWarning ) self._consumer_token = (user, password) self._access_token: tuple[str, str] | None = None diff --git a/scripts/replace.py b/scripts/replace.py index c4fc4a6..3bf3ca6 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -602,15 +602,8 @@ return False - def apply_replacements(self, original_text, applied, page=None): - """Apply all replacements to the given text. - - :rtype: str, set - """ - if page is None: - pywikibot.warn( - 'You must pass the target page as the "page" parameter to ' - 'apply_replacements().', DeprecationWarning, stacklevel=2) + def apply_replacements(self, original_text, applied, page) -> str: + """Apply all replacements to the given text.""" new_text = original_text exceptions = _get_text_exceptions(self.exceptions) skipped_containers = set() @@ -621,8 +614,7 @@ and replacement.container.name in skipped_containers): continue - if page is not None and self.isTitleExcepted( - page.title(), replacement.exceptions): + if self.isTitleExcepted(page.title(), replacement.exceptions): if replacement.container: pywikibot.info( f'Skipping fix "{replacement.container.name}" on ' -- To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1103898?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Change-Id: Ia6057f3126f33ef8430bb57b76d6653e9fe69e9b Gerrit-Change-Number: 1103898 Gerrit-PatchSet: 3 Gerrit-Owner: Xqt <i...@gno.de> Gerrit-Reviewer: Xqt <i...@gno.de> Gerrit-Reviewer: jenkins-bot
_______________________________________________ Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org