jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/991882 )
Change subject: [flake8] solve some flake8 issues
......................................................................
[flake8] solve some flake8 issues
Change-Id: Icf7ae49daa4d8ff874de419abdf07535d9b6174e
---
M pywikibot/page/_user.py
M pywikibot/site/_apisite.py
M pywikibot/site/_siteinfo.py
M scripts/maintenance/unidata.py
M setup.py
M tests/utils.py
6 files changed, 24 insertions(+), 13 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_user.py b/pywikibot/page/_user.py
index 28ebd9c..2aee039 100644
--- a/pywikibot/page/_user.py
+++ b/pywikibot/page/_user.py
@@ -1,6 +1,6 @@
"""Object representing a Wiki user."""
#
-# (C) Pywikibot team, 2009-2022
+# (C) Pywikibot team, 2009-2024
#
# Distributed under the terms of the MIT license.
#
@@ -261,10 +261,8 @@
mailrequest = self.site.simple_request(**params)
maildata = mailrequest.submit()
- if 'emailuser' in maildata \
- and maildata['emailuser']['result'] == 'Success':
- return True
- return False
+ return ('emailuser' in maildata
+ and maildata['emailuser']['result'] == 'Success')
def block(self, *args, **kwargs):
"""
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 9aa95d4..37bbc8e 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -1,6 +1,6 @@
"""Objects representing API interface to MediaWiki site."""
#
-# (C) Pywikibot team, 2008-2023
+# (C) Pywikibot team, 2008-2024
#
# Distributed under the terms of the MIT license.
#
@@ -1280,7 +1280,7 @@
def image_repository(self) -> BaseSite | None:
"""Return Site object for image repository e.g. commons."""
code, fam = self.shared_image_repository()
- if bool(code or fam):
+ if code or fam:
return pywikibot.Site(code, fam, self.username())
return None
diff --git a/pywikibot/site/_siteinfo.py b/pywikibot/site/_siteinfo.py
index 5a1dd48..cf7251a 100644
--- a/pywikibot/site/_siteinfo.py
+++ b/pywikibot/site/_siteinfo.py
@@ -1,6 +1,6 @@
"""Objects representing site info data contents."""
#
-# (C) Pywikibot team, 2008-2023
+# (C) Pywikibot team, 2008-2024
#
# Distributed under the terms of the MIT license.
#
@@ -82,7 +82,7 @@
if prop in ('namespaces', 'magicwords'):
for index, value in enumerate(data):
# namespaces uses a dict, while magicwords uses a list
- key = index if type(data) is list else value
+ key = index if isinstance(data, list) else value
for p in Siteinfo.BOOLEAN_PROPS[prop]:
data[key][p] = p in data[key]
else:
diff --git a/scripts/maintenance/unidata.py b/scripts/maintenance/unidata.py
index f2284c4..cb20643 100755
--- a/scripts/maintenance/unidata.py
+++ b/scripts/maintenance/unidata.py
@@ -10,7 +10,7 @@
.. versionadded:: 8.4
"""
#
-# (C) Pywikibot team, 2018-2023
+# (C) Pywikibot team, 2018-2024
#
# Distributed under the terms of the MIT license.
#
@@ -38,7 +38,7 @@
chars = []
uppers = []
wikilinks = ''
- for i in range(0, maxunicode + 1):
+ for i in range(maxunicode + 1):
c = chr(i)
uc = c.upper()
if uc != c:
diff --git a/setup.py b/setup.py
index 3a23a45..0275e71 100755
--- a/setup.py
+++ b/setup.py
@@ -24,6 +24,8 @@
#
# Distributed under the terms of the MIT license.
#
+from __future__ import annotations
+
import os
import re
import sys
@@ -57,6 +59,8 @@
'flake8-bugbear>=23.3.12',
'flake8-comprehensions>=3.13.0',
'flake8-docstrings>=1.4.0',
+ 'flake8-executable',
+ 'flake8-future-annotations',
'flake8-mock-x2',
'flake8-print>=5.0.0',
'flake8-quotes>=3.3.2',
diff --git a/tests/utils.py b/tests/utils.py
index 7269ea5..bfa2760 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -390,7 +390,7 @@
def image_repository(self):
"""Return Site object for image repository e.g. commons."""
code, fam = self.shared_image_repository()
- if bool(code or fam):
+ if code or fam:
return pywikibot.Site(code, fam, self.username(),
interface=self.__class__)
return None
@@ -411,7 +411,7 @@
'wikivoyage'):
code, fam = None, None
- if bool(code or fam):
+ if code or fam:
return pywikibot.Site(code, fam, self.username(),
interface=DryDataSite)
return None
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/991882
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Icf7ae49daa4d8ff874de419abdf07535d9b6174e
Gerrit-Change-Number: 991882
Gerrit-PatchSet: 13
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/991742 )
Change subject: [flake8] fix bugbear 24.1.17 issues
......................................................................
[flake8] fix bugbear 24.1.17 issues
All of the B038 issues are not related to us and are false positives.
We can ignore them. I leave a comment for the reason.
Bug: T355372
Change-Id: I47462971df848293380727f4645d7b2fe61d7725
---
M pywikibot/data/api/__init__.py
M pywikibot/proofreadpage.py
M scripts/dataextend.py
3 files changed, 27 insertions(+), 7 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/data/api/__init__.py b/pywikibot/data/api/__init__.py
index 530f15b..9f289ab 100644
--- a/pywikibot/data/api/__init__.py
+++ b/pywikibot/data/api/__init__.py
@@ -1,6 +1,6 @@
"""Interface to Mediawiki's api.php."""
#
-# (C) Pywikibot team, 2014-2023
+# (C) Pywikibot team, 2014-2024
#
# Distributed under the terms of the MIT license.
#
@@ -57,7 +57,10 @@
if isinstance(family, SubdomainFamily):
for cookie in http.cookie_jar:
if family.domain == cookie.domain:
- http.cookie_jar.clear(cookie.domain, cookie.path, cookie.name)
+ # ignore B038: iterating over cookies already uses a list,
+ # created in cookiejar.deepvalues()
+ http.cookie_jar.clear( # noqa: B038
+ cookie.domain, cookie.path, cookie.name)
# Bug: T113120, T228841
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py
index 7e7c24e..8f217e9 100644
--- a/pywikibot/proofreadpage.py
+++ b/pywikibot/proofreadpage.py
@@ -22,7 +22,7 @@
"""
#
-# (C) Pywikibot team, 2015-2023
+# (C) Pywikibot team, 2015-2024
#
# Distributed under the terms of the MIT license.
#
@@ -543,7 +543,8 @@
if self._num is not None:
for page in what_links_here:
if page.title(with_ns=False) == self._base:
- what_links_here.remove(page)
+ # ignore B038, we break the loop after removal
+ what_links_here.remove(page) # noqa: B038
self._index = (page, what_links_here)
break
diff --git a/scripts/dataextend.py b/scripts/dataextend.py
index e63cf36..0c97fe9 100755
--- a/scripts/dataextend.py
+++ b/scripts/dataextend.py
@@ -54,7 +54,7 @@
.. versionadded:: 7.2
"""
#
-# (C) Pywikibot team, 2020-2023
+# (C) Pywikibot team, 2020-2024
#
# Distributed under the terms of the MIT license.
#
@@ -967,7 +967,9 @@
claim[0]])].addSources(sourcedata)
else:
if claim[0] not in propsdone:
- propstodo.append(claim[0])
+ # DequeGenerator is intended to add items
+ # during generation, therefore ignore B038
+ propstodo.append(claim[0]) # noqa: B038
createdclaim = pywikibot.Claim(self.site, claim[0])
@@ -1093,7 +1095,8 @@
0]])].addSources(sourcedata)
except AttributeError:
if prop not in propsdone:
- propstodo.append(prop)
+ # ignore B038 due to DequeGenerator
+ propstodo.append(prop) # noqa: B038
pywikibot.info('Sourcing failed')
for language, description in analyzer.getdescriptions():
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/991742
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I47462971df848293380727f4645d7b2fe61d7725
Gerrit-Change-Number: 991742
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <dalangi-ctr(a)wikimedia.org>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/988662 )
Change subject: fix test for bulba:bulba wiki
......................................................................
fix test for bulba:bulba wiki
Bug: T354535
Change-Id: I19eba388388698452b9a2f957376fa456c11c342
---
M tests/link_tests.py
1 file changed, 34 insertions(+), 8 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/tests/link_tests.py b/tests/link_tests.py
index f2df2b6..ad15a9e 100755
--- a/tests/link_tests.py
+++ b/tests/link_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""Test Link functionality."""
#
-# (C) Pywikibot team, 2014-2022
+# (C) Pywikibot team, 2014-2024
#
# Distributed under the terms of the MIT license.
#
@@ -866,21 +866,37 @@
code = 'en'
def test_non_wiki_prefix(self):
- """Test that Link fails if the interwiki prefix is not a wiki."""
+ """Test that Link fails if the interwiki prefix is not a wiki.
+
+ *bugzilla* does not return a json content but redirects to phab.
+ api.Request._json_loads cannot detect this problem and raises a
+ :exc:`exceptions.SiteDefinitionError`. The site is created
+ anyway but the title cannot be parsed:
+ """
link = Link('bugzilla:1337', source=self.site)
- # bugzilla does not return a json content but redirects to phab.
- # api.Request._json_loads cannot detect this problem and raises
- # a SiteDefinitionError. The site is created anyway but the title
- # cannot be parsed
with self.assertRaises(SiteDefinitionError):
link.site
self.assertEqual(link.site.sitename, 'wikimedia:wikimedia')
self.assertTrue(link._is_interwiki)
def test_other_wiki_prefix(self):
- """Test that Link fails if the interwiki prefix is a unknown family."""
+ """Test that Link fails if the interwiki prefix is a unknown family.
+
+ Sometimes *bulba* does not return a json content but a security
+ script. api.Request._json_loads raises a
+ :exc:`exceptions.SiteDefinitionError` for an invalid
+ :class:`Autofamily('bulbapedia.bulbagarden.net')
+ <family.AutoFamily>`. The site is created anyway but the title
+ cannot be parsed in such case.
+ """
link = Link('bulba:title on auto-generated Site', source=self.site)
- self.assertEqual(link.title, 'Title on auto-generated Site')
+ try:
+ link.site
+ except SiteDefinitionError as e:
+ self.assertEqual(
+ str(e), "Invalid AutoFamily('bulbapedia.bulbagarden.net')")
+ else:
+ self.assertEqual(link.title, 'Title on auto-generated Site')
self.assertEqual(link.site.sitename, 'bulba:bulba')
self.assertTrue(link._is_interwiki)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/988662
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I19eba388388698452b9a2f957376fa456c11c342
Gerrit-Change-Number: 988662
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged