jenkins-bot submitted this change.

View Change

Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
[cleanup] Remove ArgumentDeprecationWarning for several scripts

remove issue_deprecation_warning for outdated options which are
printed as ArgumentDeprecationWarning (which is both, a FutureWarning
and a UserWarning) since years

Change-Id: I55f8228b531666c5eb08452d939c97da35beb792
---
M pywikibot/pagegenerators.py
M scripts/checkimages.py
M scripts/delete.py
M scripts/imageuncat.py
M scripts/movepages.py
M scripts/nowcommons.py
M scripts/pagefromfile.py
M scripts/redirect.py
M scripts/replace.py
M scripts/table2wiki.py
M scripts/template.py
M scripts/unusedfiles.py
M tests/pagegenerators_tests.py
13 files changed, 31 insertions(+), 182 deletions(-)

diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index b9b163e..9b8e460 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -31,7 +31,6 @@
from functools import partial
from itertools import zip_longest
from requests.exceptions import ReadTimeout
-from warnings import warn

import pywikibot

@@ -41,7 +40,6 @@
DequeGenerator,
filter_unique,
intersect_generators,
- issue_deprecation_warning,
itergroup,
ModuleDeprecationWrapper,
redirect_func,
@@ -50,11 +48,7 @@
from pywikibot import date, config, i18n, xmlreader
from pywikibot.bot import ShowingListOption
from pywikibot.comms import http
-from pywikibot.exceptions import (
- ArgumentDeprecationWarning,
- ServerError,
- UnknownExtension,
-)
+from pywikibot.exceptions import ServerError, UnknownExtension
from pywikibot.proofreadpage import ProofreadPage


@@ -586,43 +580,30 @@
return dupfiltergen

@deprecated_args(arg='category')
- def getCategory(self, category):
+ def getCategory(self, category: str) -> tuple:
"""
Return Category and start as defined by category.

@param category: category name with start parameter
- @type category: str
- @rtype: tuple
"""
- if category and category.startswith('-'):
- categoryname = category.partition(':')[2]
- issue_deprecation_warning(
- 'The usage of "{0}" as actual parameter of '
- 'pagegenerators.getCategory'.format(category),
- categoryname, depth=3,
- warning_class=ArgumentDeprecationWarning,
- since='20141019')
- else:
- categoryname = category
-
- if not categoryname:
- categoryname = i18n.input(
+ if not category:
+ category = i18n.input(
'pywikibot-enter-category-name',
fallback_prompt='Please enter the category name:')
- categoryname = categoryname.replace('#', '|')
+ category = category.replace('#', '|')

- categoryname, sep, startfrom = categoryname.partition('|')
+ category, _, startfrom = category.partition('|')
if not startfrom:
startfrom = None

- # Insert Category: before category name to avoid parsing problems in
+ # Insert "Category:" before category name to avoid parsing problems in
# Link.parse() when categoryname contains ":";
# Part before ":" might be interpreted as an interwiki prefix
- prefix = categoryname.split(':', 1)[0] # whole word if ":" not present
+ prefix = category.split(':', 1)[0] # whole word if ":" not present
if prefix not in self.site.namespaces[14]:
- categoryname = '{0}:{1}'.format(
- self.site.namespace(14), categoryname)
- cat = pywikibot.Category(pywikibot.Link(categoryname,
+ category = '{}:{}'.format(
+ self.site.namespace(14), category)
+ cat = pywikibot.Category(pywikibot.Link(category,
source=self.site,
default_namespace=14))
return cat, startfrom
@@ -713,7 +694,7 @@
valid_cats = [c for _list in cats.values() for c in _list]

value = '' if value is None else value
- cat, sep, lint_from = value.partition('/')
+ cat, _, lint_from = value.partition('/')
if not lint_from:
lint_from = None

@@ -880,11 +861,7 @@

def _handle_namespaces(self, value):
"""Handle `-namespaces` argument."""
- if isinstance(self._namespaces, frozenset):
- warn('Cannot handle arg -namespaces as namespaces can not '
- 'be altered after a generator is created.',
- ArgumentDeprecationWarning, 3)
- return True
+ assert not isinstance(self._namespaces, frozenset)
if not value:
value = pywikibot.input('What namespace are you filtering on?')
NOT_KEY = 'not:'
@@ -1119,27 +1096,6 @@
(temp[0][0], temp[0][1], dict(temp[1:]), ifnot))
return True

- @staticmethod
- def _handle_yahoo(value):
- """Handle `-yahoo` argument."""
- issue_deprecation_warning('-yahoo', depth=3,
- warning_class=ArgumentDeprecationWarning,
- since='20181125')
-
- @staticmethod
- def _handle_untagged(value):
- """Handle `-untagged` argument."""
- issue_deprecation_warning('-untagged', depth=3,
- warning_class=ArgumentDeprecationWarning,
- since='20161116')
-
- @staticmethod
- def _handle_wikidataquery(value):
- """Handle `-wikidataquery` argument."""
- issue_deprecation_warning('-wikidataquery', depth=3,
- warning_class=ArgumentDeprecationWarning,
- since='20170520')
-
def _handle_sparqlendpoint(self, value):
"""Handle `-sparqlendpoint` argument."""
if not value:
@@ -1198,7 +1154,7 @@
value = arg
arg = '-' + self._positional_arg_name
else:
- arg, sep, value = arg.partition(':')
+ arg, _, value = arg.partition(':')

if value == '':
value = None
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index e4271eb..1d612fa 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -92,12 +92,11 @@
import pywikibot

from pywikibot.bot import suggest_help
-from pywikibot.exceptions import ArgumentDeprecationWarning, NotEmailableError
+from pywikibot.exceptions import NotEmailableError
from pywikibot.family import Family
from pywikibot import i18n
from pywikibot import pagegenerators as pg
from pywikibot.site import Namespace
-from pywikibot.tools import issue_deprecation_warning

###############################################################################
# <--------------------------- Change only below! --------------------------->#
@@ -1549,15 +1548,9 @@
'How many files do you want to check?'))
else:
limit = int(arg[7:])
- elif arg.startswith(('-sleep', '-time')):
- if arg.startswith('-sleep'):
- length = len('-sleep')
- else:
- issue_deprecation_warning('-time', '-sleep', 2,
- ArgumentDeprecationWarning,
- since='20151209')
- length = len('-time')
- if len(arg) == length:
+ elif arg.startswith('-sleep'):
+ length = len(arg)
+ if length == len('-sleep'):
time_sleep = int(pywikibot.input(
'How many seconds do you want runs to be apart?'))
else:
@@ -1568,12 +1561,7 @@
logFullError = False
elif arg == '-commons':
commonsActive = True
- elif arg == '-duplicatesreport' or arg == '-duplicatereport':
- if arg == '-duplicatereport':
- issue_deprecation_warning('-duplicatereport',
- '-duplicatesreport',
- 2, ArgumentDeprecationWarning,
- since='20161116')
+ elif arg == '-duplicatesreport':
duplicatesReport = True
elif arg.startswith('-duplicates'):
duplicatesActive = True
diff --git a/scripts/delete.py b/scripts/delete.py
index 0db37bc..ac63729 100755
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -59,11 +59,9 @@
import collections

from typing import Set
-from warnings import warn

import pywikibot

-from pywikibot import exceptions
from pywikibot import i18n, pagegenerators
from pywikibot.bot import MultipleSitesBot, CurrentPageBot
from pywikibot.page import Page
@@ -256,10 +254,6 @@
summary = pywikibot.input('Enter a reason for the deletion:')
else:
summary = arg[len('-summary:'):]
- elif arg.startswith('-images'):
- warn('-image option is deprecated. Please use -imageused instead.',
- exceptions.ArgumentDeprecationWarning)
- local_args.append('-imageused' + arg[7:])
elif arg.startswith('-undelete'):
options['undelete'] = True
elif arg.startswith('-isorphan'):
diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py
index 3e03bf8..5151df9 100755
--- a/scripts/imageuncat.py
+++ b/scripts/imageuncat.py
@@ -1354,14 +1354,6 @@
'The usage of "-yesterday"',
'-logevents:"upload,,YYYYMMDD,YYYYMMDD"',
2, ArgumentDeprecationWarning, since='20160305')
- elif arg.startswith('-recentchanges'):
- if param_value is None:
- arg = arg + ':120,70'
- issue_deprecation_warning(
- '-recentchanges without parameters',
- '-recentchanges:offset,duration',
- 2, ArgumentDeprecationWarning, since='20160320')
- gen_factory.handleArg(arg)
else:
gen_factory.handleArg(arg)

diff --git a/scripts/movepages.py b/scripts/movepages.py
index f6739dd..8c82286 100755
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -42,8 +42,6 @@

from pywikibot import i18n, pagegenerators
from pywikibot.bot import MultipleSitesBot
-from pywikibot.exceptions import ArgumentDeprecationWarning
-from pywikibot.tools import issue_deprecation_warning


# This is required for the text that is shown when you run this script
@@ -192,12 +190,7 @@
for arg in local_args:
if genFactory.handleArg(arg):
continue
- if arg == '-pairs' or arg.startswith('-pairs:'):
- issue_deprecation_warning(
- '-pairs',
- '-pairsfile',
- 2, ArgumentDeprecationWarning, since='20160304')
- elif arg.startswith('-pairsfile'):
+ if arg.startswith('-pairsfile'):
if len(arg) == len('-pairsfile'):
filename = pywikibot.input(
'Enter the name of the file containing pairs:')
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index 48f4a4a..79c5135 100755
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -51,16 +51,13 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
from itertools import chain
import sys

import pywikibot
from pywikibot import Bot, i18n
-from pywikibot.exceptions import ArgumentDeprecationWarning
from pywikibot import pagegenerators as pg
-from pywikibot.tools import filter_unique, issue_deprecation_warning
+from pywikibot.tools import filter_unique
from pywikibot.tools.formatter import color_format

from scripts.image import ImageRobot as ImageBot
@@ -190,7 +187,7 @@
'replaceloose': False,
'replaceonly': False,
})
- super(NowCommonsDeleteBot, self).__init__(**kwargs)
+ super().__init__(**kwargs)

self.site = pywikibot.Site()
if not self.site.has_image_repository:
@@ -390,14 +387,6 @@
if arg == '-replacealways':
options['replace'] = True
options['replacealways'] = True
- elif arg == '-hash': # T132303
- raise NotImplementedError(
- "The '-hash' argument is not implemented anymore.")
- elif arg == '-autonomous':
- issue_deprecation_warning('-autonomous', '-always', 2,
- ArgumentDeprecationWarning,
- since='20140724')
- options['always'] = True
elif arg.startswith('-'):
if arg[1:] in ('always', 'replace', 'replaceloose', 'replaceonly'):
options[arg[1:]] = True
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 537ae7c..de480d8 100755
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -70,13 +70,11 @@
import re

from typing import Generator, Tuple
-from warnings import warn

import pywikibot

from pywikibot import config, i18n
from pywikibot.bot import CurrentPageBot, OptionHandler, SingleSiteBot
-from pywikibot.exceptions import ArgumentDeprecationWarning


class NoTitle(Exception):
@@ -301,12 +299,7 @@
arg, sep, value = arg.partition(':')
option = arg.partition('-')[2]
# reader options
- if option == 'start':
- r_options['begin'] = value
- warn('-start param (text that marks the beginning) of a page has '
- 'been deprecated in favor of begin; make sure to use the '
- 'updated param.', ArgumentDeprecationWarning)
- elif option in ('begin', 'end', 'titlestart', 'titleend', 'title'):
+ if option in ('begin', 'end', 'titlestart', 'titleend', 'title'):
r_options[option] = value
elif option == 'file':
filename = value
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 3261cc4..69cf441 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -83,9 +83,7 @@
from pywikibot import i18n, xmlreader
from pywikibot.bot import (ExistingPageBot, OptionHandler, RedirectPageBot,
SingleSiteBot)
-from pywikibot.exceptions import ArgumentDeprecationWarning
from pywikibot.textlib import extract_templates_and_params_regex_simple
-from pywikibot.tools import issue_deprecation_warning


def space_to_underscore(link) -> str:
@@ -731,13 +729,8 @@
gen_options[option] = int(value)
elif option in ('page', 'start', 'until'):
gen_options[option] = value
- elif option in ('limit', 'total'):
+ elif option == 'limit':
options['limit'] = gen_options['limit'] = int(value)
- if option == 'total':
- issue_deprecation_warning('The usage of "{0}"'.format(arg),
- '-limit', 2,
- ArgumentDeprecationWarning,
- since='20190120')
else:
pywikibot.output('Unknown argument: ' + arg)

diff --git a/scripts/replace.py b/scripts/replace.py
index d725073..5e6ed05 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -150,17 +150,11 @@

import pywikibot
from pywikibot import editor
-from pywikibot.exceptions import ArgumentDeprecationWarning
# Imports predefined replacements tasks from fixes.py
from pywikibot import fixes
from pywikibot import i18n, textlib, pagegenerators
from pywikibot.bot import ExistingPageBot, SingleSiteBot
-from pywikibot.tools import (
- chars,
- deprecated,
- deprecated_args,
- issue_deprecation_warning,
-)
+from pywikibot.tools import chars, deprecated, deprecated_args


# This is required for the text that is shown when you run this script
@@ -384,7 +378,7 @@
return _get_text_exceptions(self.fix_set.exceptions or {})


-class XmlDumpReplacePageGenerator(object):
+class XmlDumpReplacePageGenerator:

"""
Iterator that will yield Pages that might contain text to replace.
@@ -893,11 +887,7 @@
xmlFilename = i18n.input('pywikibot-enter-xml-filename')
else:
xmlFilename = arg[5:]
- elif arg.startswith(('-sql', '-mysqlquery')):
- if arg.startswith('-sql'):
- issue_deprecation_warning('The usage of "-sql"', '-mysqlquery',
- 1, ArgumentDeprecationWarning,
- since='20180617')
+ elif arg.startswith('-mysqlquery'):
useSql = True
sql_query = arg.partition(':')[2]
elif arg.startswith('-excepttitle:'):
@@ -930,11 +920,6 @@
edit_summary = True
elif arg.startswith('-manualinput'):
manual_input = True
- elif arg.startswith('-replacementfile'):
- issue_deprecation_warning(
- '-replacementfile',
- '-pairsfile',
- 2, ArgumentDeprecationWarning, since='20160304')
elif arg.startswith('-pairsfile'):
if len(commandline_replacements) % 2:
replacement_file_arg_misplaced = True
diff --git a/scripts/table2wiki.py b/scripts/table2wiki.py
index 0756847..925daa4 100644
--- a/scripts/table2wiki.py
+++ b/scripts/table2wiki.py
@@ -56,9 +56,7 @@

from pywikibot.bot import (SingleSiteBot, ExistingPageBot, NoRedirectPageBot,
suggest_help, input_yn)
-from pywikibot.exceptions import ArgumentDeprecationWarning
from pywikibot.textlib import replaceExcept
-from pywikibot.tools import issue_deprecation_warning

# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -533,25 +531,15 @@
gen_factory = pagegenerators.GeneratorFactory(positional_arg_name='page')

for arg in local_args:
- option, sep, value = arg.partition(':')
+ option, _, value = arg.partition(':')
if option == '-xml':
filename = value or pywikibot.input(
"Please enter the XML dump's filename:")
gen = TableXmlDumpPageGenerator(filename)
- elif option == '-auto':
- issue_deprecation_warning(
- 'The usage of "-auto"', '-always',
- 1, ArgumentDeprecationWarning, since='20170205')
- options['always'] = True
elif option in ['-always', '-quiet', '-skipwarning']:
options[option[1:]] = True
else:
- if option in ('-sql', '-mysqlquery'):
- if option == '-sql':
- issue_deprecation_warning(
- 'The usage of "-sql"', '-mysqlquery',
- 1, ArgumentDeprecationWarning, since='20170205')
-
+ if option == '-mysqlquery':
query = value or """
SELECT page_namespace, page_title
FROM page JOIN text ON (page_id = old_id)
diff --git a/scripts/template.py b/scripts/template.py
index 78accae..2c18a7b 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -113,13 +113,11 @@
import re

from itertools import chain
-from warnings import warn

import pywikibot

from pywikibot import i18n, pagegenerators, textlib
from pywikibot.bot import SingleSiteBot
-from pywikibot.exceptions import ArgumentDeprecationWarning
from pywikibot.pagegenerators import XMLDumpPageGenerator
from pywikibot.tools import deprecated, filter_unique
from scripts.replace import ReplaceRobot as ReplaceBot
@@ -280,12 +278,6 @@
# read command line parameters
local_args = pywikibot.handle_args(args)

- # Avoid conflicts with pagegenerators.py parameters.
- if any(arg.startswith('-category:') for arg in local_args):
- warn('-category (to append a category to each edited page) has been'
- ' renamed to -addcat; make sure you are using the correct param.',
- ArgumentDeprecationWarning)
-
site = pywikibot.Site()
gen_factory = pagegenerators.GeneratorFactory()
for arg in local_args:
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index d563a80..7ee2549 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -16,14 +16,10 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import pywikibot
from pywikibot import i18n, pagegenerators
from pywikibot.bot import SingleSiteBot, AutomaticTWSummaryBot, ExistingPageBot
-from pywikibot.exceptions import ArgumentDeprecationWarning
from pywikibot.flow import Board
-from pywikibot.tools import issue_deprecation_warning

template_to_the_image = {
'meta': '{{Orphan file}}',
@@ -51,7 +47,7 @@
self.availableOptions.update({
'nouserwarning': False # do not warn uploader
})
- super(UnusedFilesBot, self).__init__(**kwargs)
+ super().__init__(**kwargs)

self.template_image = i18n.translate(self.site,
template_to_the_image)
@@ -129,11 +125,6 @@
arg, sep, value = arg.partition(':')
if arg == '-limit':
total = value
- elif arg == '-total':
- total = value
- issue_deprecation_warning('The usage of "{0}"'.format(arg),
- '-limit', 2, ArgumentDeprecationWarning,
- since='20190120')
else:
options[arg[1:]] = True

diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index ffbe993..aef081b 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -672,13 +672,8 @@
gf.handleArg('-ns:1,6')
self.assertEqual(gf.namespaces, {1, 6})
self.assertIsInstance(gf.namespaces, frozenset)
- with suppress_warnings(
- 'Cannot handle arg -namespaces as namespaces can not be altered '
- 'after a generator is created.',
- pywikibot.exceptions.ArgumentDeprecationWarning
- ):
+ with self.assertRaises(AssertionError):
gf.handleArg('-ns:0')
-
self.assertEqual(gf.namespaces, {1, 6})

def test_unsupported_quality_level_filter(self):

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I55f8228b531666c5eb08452d939c97da35beb792
Gerrit-Change-Number: 612556
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged