jenkins-bot merged this change.

View Change

Approvals: D3r1ck01: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup] Remove unused code in 4 files

Removed errors reported by vulture in files:
* pywikibot/family.py (unused variable (function argument))
* pywikibot/login.py (unused variable (function argument))
* pywikibot/page.py (unused variable (function argument))

For the 3 unused arguments removed mentioned above, their corresponding
entries in the decorator @remove_last_args() were added.

Documentation was updated for each method updated.

The class YahooSearchPageGenerator has been removed. The corresponding
decorator ModuleDeprecationWrapper was used to indicate its deprecation.
The argument to use YahooSearchPageGenerator has been deprecated as well
and its documentation.

Bug: T203395
Bug: T106085
Change-Id: Ie1d412cc3a6316da3781865931feead65576d0c3
---
M pywikibot/family.py
M pywikibot/login.py
M pywikibot/page.py
M pywikibot/pagegenerators.py
4 files changed, 16 insertions(+), 77 deletions(-)

diff --git a/pywikibot/family.py b/pywikibot/family.py
index 6802abb..b3276ca 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -22,7 +22,7 @@
from pywikibot import config
from pywikibot.exceptions import UnknownFamily, FamilyMaintenanceWarning
from pywikibot.tools import (
- deprecated, deprecated_args, issue_deprecation_warning,
+ deprecated, deprecated_args, remove_last_args, issue_deprecation_warning,
FrozenDict, classproperty
)

@@ -1416,7 +1416,8 @@
return (None, None)

# Deprecated via __getattribute__
- def shared_data_repository(self, code, transcluded=False):
+ @remove_last_args(['transcluded'])
+ def shared_data_repository(self, code):
"""Return the shared Wikibase repository, if any."""
repo = pywikibot.Site(code, self).data_repository()
if repo is not None:
diff --git a/pywikibot/login.py b/pywikibot/login.py
index 7161118..bb8e954 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -26,7 +26,8 @@

from pywikibot import config, __url__
from pywikibot.exceptions import NoUsername
-from pywikibot.tools import deprecated_args, normalize_username, PY2
+from pywikibot.tools import (deprecated_args, remove_last_args,
+ normalize_username, PY2)

if not PY2:
unicode = basestring = str
@@ -179,15 +180,11 @@
# No bot policies on other sites
return True

- def getCookie(self, remember=True, captcha=None):
+ @remove_last_args(['remember', 'captcha'])
+ def getCookie(self):
"""
Login to the site.

- @param remember: Remember login (default: True)
- @type remember: bool
- @param captchaId: A dictionary containing the captcha id and answer,
- if any
-
@return: cookie data if successful, None otherwise.
"""
# THIS IS OVERRIDDEN IN data/api.py
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 6d51e2c..f5f053f 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1859,8 +1859,9 @@

@deprecated_args(
throttle=None, deleteAndMove='noredirect', movetalkpage='movetalk')
+ @remove_last_args(['safe'])
def move(self, newtitle, reason=None, movetalk=True, sysop=False,
- noredirect=False, safe=True):
+ noredirect=False):
"""
Move this page to a new title.

@@ -1870,14 +1871,11 @@
@param sysop: Try to move using sysop account, if available
@param noredirect: if move succeeds, delete the old page
(usually requires sysop privileges, depending on wiki settings)
- @param safe: If false, attempt to delete existing page at newtitle
- (if there is one) and then move this page to that title
"""
if reason is None:
pywikibot.output('Moving %s to [[%s]].'
% (self.title(as_link=True), newtitle))
reason = pywikibot.input('Please enter a reason for the move:')
- # TODO: implement "safe" parameter (Is this necessary ?)
# TODO: implement "sysop" parameter
return self.site.movepage(self, newtitle, reason,
movetalk=movetalk,
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 14fe1fd..9555c39 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -43,6 +43,7 @@
issue_deprecation_warning,
IteratorNextMixin,
itergroup,
+ ModuleDeprecationWrapper,
redirect_func,
)

@@ -283,10 +284,6 @@
config.py for instructions.
Argument can also be given as "-google:searchstring".

--yahoo Work on all pages that are found in a Yahoo search.
- Depends on python module pYsearch. See yahoo_appid in
- config.py for instructions.
-
-page Work on a single page. Argument can also be given as
"-page:pagetitle", and supplied multiple times for
multiple pages.
@@ -1110,7 +1107,8 @@

def _handle_yahoo(self, value):
"""Handle `-yahoo` argument."""
- return YahooSearchPageGenerator(value, site=self.site)
+ issue_deprecation_warning('-yahoo', None, 3,
+ ArgumentDeprecationWarning, since='20181125')

@staticmethod
def _handle_untagged(value):
@@ -2643,65 +2641,6 @@
# following classes just ported from version 1 without revision; not tested


-class YahooSearchPageGenerator(object):
-
- """
- Page generator using Yahoo! search results.
-
- To use this generator, you need to install the package 'pYsearch'.
- https://pypi.org/project/pYsearch
-
- To use this generator, install pYsearch
- """
-
- @deprecated_args(count='total')
- def __init__(self, query=None, total=100, site=None):
- """
- Initializer.
-
- @param site: Site for generator results.
- @type site: L{pywikibot.site.BaseSite}
- """
- raise RuntimeError(
- 'pagegenerator YahooSearchPageGenerator is not functional.\n'
- 'See https://phabricator.wikimedia.org/T106085')
-
- self.query = query or pywikibot.input('Please enter the search query:')
- self.total = total
- if site is None:
- site = pywikibot.Site()
- self.site = site
-
- def queryYahoo(self, query):
- """Perform a query using python package 'pYsearch'."""
- try:
- from yahoo.search.web import WebSearch
- except ImportError:
- pywikibot.error('ERROR: generator YahooSearchPageGenerator '
- "depends on package 'pYsearch'.\n"
- 'To install, please run: pip install pYsearch')
- exit(1)
-
- srch = WebSearch(config.yahoo_appid, query=query, results=self.total)
- dom = srch.get_results()
- results = srch.parse_results(dom)
- for res in results:
- url = res.Url
- yield url
-
- def __iter__(self):
- """Iterate results."""
- # restrict query to local site
- localQuery = '%s site:%s' % (self.query, self.site.hostname())
- base = 'http://%s%s' % (self.site.hostname(),
- self.site.article_path)
- for url in self.queryYahoo(localQuery):
- if url[:len(base)] == base:
- title = url[len(base):]
- page = pywikibot.Page(pywikibot.Link(title, pywikibot.Site()))
- yield page
-
-
class GoogleSearchPageGenerator(object):

"""
@@ -3146,3 +3085,7 @@
if __name__ == '__main__':
pywikibot.output('Pagegenerators cannot be run as script - are you '
'looking for listpages.py?')
+
+wrapper = ModuleDeprecationWrapper(__name__)
+wrapper._add_deprecated_attr('YahooSearchPageGenerator', replacement_name='',
+ since='20181128')

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie1d412cc3a6316da3781865931feead65576d0c3
Gerrit-Change-Number: 474727
Gerrit-PatchSet: 6
Gerrit-Owner: Nils ANDRE <nils.andre.chang@gmail.com>
Gerrit-Reviewer: D3r1ck01 <alangiderick@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Nils ANDRE <nils.andre.chang@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)