John Vandenberg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/234953
Change subject: Fix flake8 errors
......................................................................
Fix flake8 errors
Remove DataSite methods that return NotImplemented,
as it is unmaintainable.
Add site module to mandatory flake8 rule
Change-Id: I8cf395f161a81c77a2eb723624b4170e2e3c53e1
---
M pywikibot/site.py
M tox.ini
2 files changed, 42 insertions(+), 71 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/53/234953/1
diff --git a/pywikibot/site.py b/pywikibot/site.py
index e50e8ae..55920dc 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -388,7 +388,7 @@
"""Return a dict of the builtin namespaces."""
return dict((i, cls(i, use_image_name=use_image_name,
case=cls.default_case(i, case)))
- for i in range(-2, 16))
+ for i in range(-2, 16))
@staticmethod
def normalize_name(name):
@@ -546,7 +546,7 @@
result = [NotImplemented if isinstance(ns, bool) else
NamespacesDict._lookup_name(ns, namespaces)
if isinstance(ns, basestring) and
- not ns.lstrip('-').isdigit() else
+ not ns.lstrip('-').isdigit() else
namespaces[int(ns)] if int(ns) in namespaces
else None
for ns in identifiers]
@@ -642,6 +642,7 @@
@property
@deprecated("APISite.siteinfo['case'] or Namespace.case ==
'case-sensitive'")
def nocapitalize(self):
+ """Return whether this site's default title case is case-sensitive."""
return self.siteinfo['case'] == 'case-sensitive'
@property
@@ -762,9 +763,11 @@
return SelfCallString(self.__str__())
def __repr__(self):
+ """Return internal representation."""
return 'Site("%s", "%s")' % (self.code, self.family.name)
def __hash__(self):
+ """Return hashable key."""
return hash(repr(self))
def languages(self):
@@ -1346,7 +1349,7 @@
else:
pywikibot.log(u"Unable to get siteinfo, because at least "
u"one property is unknown: '{0}'".format(
- u"', '".join(props)))
+ "', '".join(props)))
results = {}
for prop in props:
results.update(self._get_siteinfo(prop, expiry))
@@ -1655,6 +1658,7 @@
@classmethod
def fromDBName(cls, dbname):
+ """Instantiate site from database name."""
# TODO this only works for some WMF sites
site = pywikibot.Site('meta', 'meta')
req = site._request(expiry=datetime.timedelta(days=10),
@@ -2284,7 +2288,7 @@
if not hasattr(self, "_magicwords"):
magicwords = self.siteinfo.get("magicwords", cache=False)
self._magicwords = dict((item["name"], item["aliases"])
- for item in magicwords)
+ for item in magicwords)
if word in self._magicwords:
return self._magicwords[word]
@@ -2293,6 +2297,7 @@
@deprecated
def resolvemagicwords(self, wikitext):
+ """Not implemented."""
return NotImplementedError
@remove_last_args(('default', ))
@@ -2602,7 +2607,7 @@
page.title(withSection=False)):
pywikibot.warning(
u"{0}: Query on {1} returned data on '{2}'".format(
- method_name, page, pageitem['title']))
+ method_name, page, pageitem['title']))
continue
api.update_page(page, pageitem, query.props)
@@ -3028,8 +3033,8 @@
if 'tokens' in data and data['tokens']:
user_tokens = dict((key[:-5], val)
- for key, val in data['tokens'].items()
- if val != '+\\')
+ for key, val in data['tokens'].items()
+ if val != '+\\')
return user_tokens
@@ -3050,7 +3055,7 @@
if self.username(sysop) != self.user():
raise ValueError('The token for {0} was requested but only the '
'token for {1} can be retrieved.'.format(
- self.username(sysop), self.user()))
+ self.username(sysop), self.user()))
if not getalways:
raise ValueError('In pywikibot/core getToken does not support the '
'getalways parameter.')
@@ -3066,7 +3071,7 @@
if self.username(sysop) != self.user():
raise ValueError('The token for {0} was requested but only the '
'token for {1} can be retrieved.'.format(
- self.username(sysop), self.user()))
+ self.username(sysop), self.user()))
return self.tokens['patrol']
def getParsedString(self, string, keeptags=None):
@@ -3607,6 +3612,7 @@
self._update_page(category, ciquery, 'categoryinfo')
def categoryinfo(self, category):
+ """Retrieve data on contents of category."""
if not hasattr(category, "_catinfo"):
self.getcategoryinfo(category)
if not hasattr(category, "_catinfo"):
@@ -3990,6 +3996,7 @@
def logpages(self, number=50, mode='', title=None, user=None, repeat=False,
namespace=[], start=None, end=None, tag=None, newer=False,
dump=False, offset=None):
+ """Not implemented. use logevents()."""
# TODO: implement using logevents
raise NotImplementedError
@@ -4572,24 +4579,29 @@
_mv_errors = {
"noapiwrite": "API editing not enabled on %(site)s wiki",
"writeapidenied":
-"User %(user)s is not authorized to edit on %(site)s wiki",
+ "User %(user)s is not authorized to edit on %(site)s wiki",
"nosuppress":
-"User %(user)s is not authorized to move pages without creating redirects",
+ 'User %(user)s is not authorized to move pages without '
+ 'creating redirects',
"cantmove-anon":
-"""Bot is not logged in, and anon users are not authorized to move pages on
-%(site)s wiki""",
+ 'Bot is not logged in, and anon users are not authorized to '
+ 'move pages on %(site)s wiki',
"cantmove":
-"User %(user)s is not authorized to move pages on %(site)s wiki",
+ "User %(user)s is not authorized to move pages on %(site)s wiki",
"immobilenamespace":
-"Pages in %(oldnamespace)s namespace cannot be moved on %(site)s wiki",
- "articleexists": OnErrorExc(exception=ArticleExistsConflict,
on_new_page=True),
+ 'Pages in %(oldnamespace)s namespace cannot be moved on %(site)s '
+ 'wiki',
+ "articleexists":
+ OnErrorExc(exception=ArticleExistsConflict, on_new_page=True),
# "protectedpage" can happen in both directions.
"protectedpage": OnErrorExc(exception=LockedPage, on_new_page=None),
"protectedtitle": OnErrorExc(exception=LockedNoPage, on_new_page=True),
"nonfilenamespace":
-"Cannot move a file to %(newnamespace)s namespace on %(site)s wiki",
+ 'Cannot move a file to %(newnamespace)s namespace on %(site)s '
+ 'wiki',
"filetypemismatch":
-"[[%(newtitle)s]] file extension does not match content of [[%(oldtitle)s]]",
+ '[[%(newtitle)s]] file extension does not match content of '
+ '[[%(oldtitle)s]]',
}
@must_be(group='user')
@@ -5437,8 +5449,7 @@
raise pywikibot.UploadWarning(warning, upload_warnings[warning]
% {'msg': message},
file_key=_file_key,
- offset=result['offset']
- if 'offset' in result else
False)
+ offset=result.get('offset', False))
elif "result" not in result:
pywikibot.output(u"Upload: unrecognized response: %s" % result)
if result["result"] == "Success":
@@ -5884,8 +5895,8 @@
@need_extension('Flow')
def load_topiclist(self, page, format='wikitext', limit=100,
- sortby='newest', toconly=False, offset=None,
- offset_id=None, reverse=False, include_offset=False):
+ sortby='newest', toconly=False, offset=None,
+ offset_id=None, reverse=False, include_offset=False):
"""Retrieve the topiclist of a Flow board.
@param page: A Flow board
@@ -6143,6 +6154,7 @@
return super(APISite, self).__getattr__(attr)
def __repr__(self):
+ """Return internal representation."""
return 'DataSite("%s", "%s")' % (self.code, self.family.name)
@deprecated("pywikibot.PropertyPage")
@@ -6150,7 +6162,7 @@
"""Generic method to get the data for multiple Wikibase items."""
wbdata = self.get_item(source, props=props, **params)
assert props in wbdata, \
- "API wbgetentities response lacks %s key" % props
+ "API wbgetentities response lacks %s key" % props
return wbdata[props]
@deprecated("pywikibot.WikibasePage")
@@ -6163,12 +6175,12 @@
wbrequest = self._simple_request(**params)
wbdata = wbrequest.submit()
assert 'success' in wbdata, \
- "API wbgetentities response lacks 'success' key"
+ "API wbgetentities response lacks 'success' key"
assert wbdata['success'] == 1, "API 'success' key is not 1"
assert 'entities' in wbdata, \
- "API wbgetentities response lacks 'entities' key"
+ "API wbgetentities response lacks 'entities' key"
assert ids in wbdata['entities'], \
- "API wbgetentities response lacks %s key" % ids
+ "API wbgetentities response lacks %s key" % ids
return wbdata['entities'][ids]
else:
# not implemented yet
@@ -6263,6 +6275,7 @@
@must_be(group='user')
def editEntity(self, identification, data, bot=True, **kwargs):
+ """Edit entity."""
if "id" in identification and identification["id"] == "-1":
del identification["id"]
params = dict(**identification)
@@ -6284,7 +6297,7 @@
@must_be(group='user')
def addClaim(self, item, claim, bot=True, **kwargs):
-
+ """Add a claim."""
params = dict(action='wbcreateclaim',
entity=item.getID(),
baserevid=item.latest_revision_id,
@@ -6461,6 +6474,7 @@
@must_be(group='user')
def removeClaims(self, claims, bot=True, **kwargs):
+ """Remove claims."""
params = dict(action='wbremoveclaims')
if bot:
params['bot'] = 1
@@ -6623,47 +6637,3 @@
if limit is not None:
gen.set_maximum_items(limit)
return gen
-
- # deprecated BaseSite methods
- def fam(self):
- raise NotImplementedError
-
- def urlEncode(self, *args, **kwargs):
- raise NotImplementedError
-
- def getUrl(self, *args, **kwargs):
- raise NotImplementedError
-
- def linkto(self, *args, **kwargs):
- raise NotImplementedError
-
- def loggedInAs(self, *args, **kwargs):
- raise NotImplementedError
-
- def postData(self, *args, **kwargs):
- raise NotImplementedError
-
- def postForm(self, *args, **kwargs):
- raise NotImplementedError
-
- # deprecated APISite methods
- def isBlocked(self, *args, **kwargs):
- raise NotImplementedError
-
- def checkBlocks(self, *args, **kwargs):
- raise NotImplementedError
-
- def isAllowed(self, *args, **kwargs):
- raise NotImplementedError
-
- def prefixindex(self, *args, **kwargs):
- raise NotImplementedError
-
- def categories(self, *args, **kwargs):
- raise NotImplementedError
-
- def linksearch(self, *args, **kwargs):
- raise NotImplementedError
-
- def newimages(self, *args, **kwargs):
- raise NotImplementedError
diff --git a/tox.ini b/tox.ini
index 728dc58..8a286f0 100644
--- a/tox.ini
+++ b/tox.ini
@@ -64,6 +64,7 @@
pywikibot/pagegenerators.py \
pywikibot/plural.py \
pywikibot/proofreadpage.py \
+ pywikibot/site.py \
pywikibot/textlib.py \
pywikibot/throttle.py \
pywikibot/titletranslate.py \
--
To view, visit https://gerrit.wikimedia.org/r/234953
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8cf395f161a81c77a2eb723624b4170e2e3c53e1
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits