jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/979482 )
Change subject: sort imports and upgrade syntax
......................................................................
sort imports and upgrade syntax
using isort and pyupgrade
Change-Id: I180a6a9d20e9a85730e2976e28d1359be17327a1
---
M scripts/maintenance/unidata.py
M pywikibot/textlib.py
M pywikibot/__init__.py
M pywikibot/family.py
M scripts/checkimages.py
M tests/utils.py
M MANIFEST.in
M scripts/create_isbn_edition.py
M scripts/dataextend.py
M pywikibot/tools/itertools.py
M pywikibot/scripts/preload_sites.py
M pywikibot/tools/_deprecate.py
M pywikibot/backports.py
M pywikibot/_wbtypes.py
M tests/sparql_tests.py
M tests/file_tests.py
M pywikibot/tools/collections.py
M tests/site_decorators_tests.py
18 files changed, 68 insertions(+), 55 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MANIFEST.in b/MANIFEST.in
index a4f38b2..f5f1dd4 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,3 +1,3 @@
graft pywikibot/scripts/i18n/pywikibot
include CODE_OF_CONDUCT.rst
-include ROADMAP.rst
\ No newline at end of file
+include ROADMAP.rst
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index c532250..69bf268 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -76,6 +76,7 @@
from pywikibot.time import Timestamp
from pywikibot.tools import PYTHON_VERSION, normalize_username
+
__all__ = (
'__copyright__', '__description__', '__download_url__',
'__license__',
'__maintainer__', '__maintainer_email__', '__name__',
'__url__',
diff --git a/pywikibot/_wbtypes.py b/pywikibot/_wbtypes.py
index 09fb379..a39565b 100644
--- a/pywikibot/_wbtypes.py
+++ b/pywikibot/_wbtypes.py
@@ -19,6 +19,7 @@
from pywikibot.time import Timestamp
from pywikibot.tools import remove_last_args
+
if TYPE_CHECKING:
from pywikibot.site import APISite, BaseSite, DataSite
diff --git a/pywikibot/backports.py b/pywikibot/backports.py
index 02b59fe..a93a5e5 100644
--- a/pywikibot/backports.py
+++ b/pywikibot/backports.py
@@ -85,6 +85,7 @@
Type,
)
else:
+ from collections import Counter
from collections.abc import (
Container,
Generator,
@@ -93,7 +94,6 @@
Mapping,
Sequence,
)
- from collections import Counter
from re import Match, Pattern
Dict = dict # type: ignore[misc]
FrozenSet = frozenset # type: ignore[misc]
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 2e0a100..ac9d478 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -14,8 +14,8 @@
import warnings
from importlib import import_module
from itertools import chain
-from textwrap import fill
from os.path import basename, dirname, splitext
+from textwrap import fill
from typing import Optional
import pywikibot
diff --git a/pywikibot/scripts/preload_sites.py b/pywikibot/scripts/preload_sites.py
index 4d4799e..1d1b775 100755
--- a/pywikibot/scripts/preload_sites.py
+++ b/pywikibot/scripts/preload_sites.py
@@ -30,6 +30,7 @@
from pywikibot.backports import Dict, List, Set, removeprefix
from pywikibot.family import Family
+
try: # Python 3.13
from os import process_cpu_count # type: ignore[attr-defined]
except ImportError:
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index f68e6a6..ab1e416 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -18,14 +18,13 @@
Container,
Dict,
Iterable,
- Match,
List,
- Pattern,
- Tuple,
- pairwise,
+ Match,
)
from pywikibot.backports import OrderedDict as OrderedDictType
+from pywikibot.backports import Pattern
from pywikibot.backports import Sequence as SequenceType
+from pywikibot.backports import Tuple, pairwise
from pywikibot.exceptions import InvalidTitleError, SiteDefinitionError
from pywikibot.family import Family
from pywikibot.time import TZoneFixedOffset
diff --git a/pywikibot/tools/_deprecate.py b/pywikibot/tools/_deprecate.py
index 8af5878..018e355 100644
--- a/pywikibot/tools/_deprecate.py
+++ b/pywikibot/tools/_deprecate.py
@@ -28,7 +28,6 @@
import re
import sys
import types
-
from contextlib import suppress
from importlib import import_module
from inspect import getfullargspec
diff --git a/pywikibot/tools/collections.py b/pywikibot/tools/collections.py
index b3e2bdf..8b217fa 100644
--- a/pywikibot/tools/collections.py
+++ b/pywikibot/tools/collections.py
@@ -11,8 +11,9 @@
from itertools import chain
from typing import Any
-from pywikibot.backports import Dict, List
+from pywikibot.backports import Dict
from pywikibot.backports import Generator as GeneratorType
+from pywikibot.backports import List
__all__ = (
diff --git a/pywikibot/tools/itertools.py b/pywikibot/tools/itertools.py
index f1c2fb1..0c14c7e 100644
--- a/pywikibot/tools/itertools.py
+++ b/pywikibot/tools/itertools.py
@@ -14,7 +14,7 @@
from itertools import chain, zip_longest
from typing import Any
-from pywikibot.backports import batched, Generator, List
+from pywikibot.backports import Generator, List, batched
from pywikibot.logging import debug
from pywikibot.tools import deprecated, issue_deprecation_warning
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 05b4b29..7058430 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -100,9 +100,9 @@
)
from pywikibot.family import Family
from pywikibot.site import Namespace
-
from scripts.welcome import get_welcome_text
+
###############################################################################
# <--------------------------- Change only below! --------------------------->#
###############################################################################
diff --git a/scripts/create_isbn_edition.py b/scripts/create_isbn_edition.py
index 82b924b..8284dde 100755
--- a/scripts/create_isbn_edition.py
+++ b/scripts/create_isbn_edition.py
@@ -240,6 +240,7 @@
from pywikibot.config import verbose_output as verbose
from pywikibot.data import api
+
try:
import isbnlib
except ImportError as e:
diff --git a/scripts/dataextend.py b/scripts/dataextend.py
index d9b24be..5a5eb97 100755
--- a/scripts/dataextend.py
+++ b/scripts/dataextend.py
@@ -2696,7 +2696,7 @@
if sectionname == 'Weitere Angaben' and sectionfound:
continue
section = self.findbyre(
-
r'(?s)<strong>{}</strong>(.*?)</tr>'.format(sectionname), html)
+
fr'(?s)<strong>{sectionname}</strong>(.*?)</tr>', html)
if section:
sectionfound = True
result += self.findallbyre(r'(?s)[>;,]([^<>;,]*)',
section,
@@ -4647,7 +4647,7 @@
self.escapehtml = True
def getvalue(self, field, html, dtype=None):
- return
self.findbyre(r'(?s)>{}<.*?<div[^<>]*>(.*?)<'.format(field),
+ return
self.findbyre(fr'(?s)>{field}<.*?<div[^<>]*>(.*?)<',
html, dtype)
def findinstanceof(self, html: str):
@@ -5523,7 +5523,7 @@
result = super().findnames(html)
for sectionname in ['Osebno ime', 'Variante osebnega imena']:
section = self.findbyre(
-
r'(?s)<td>{}</td>.*?<a[^<>]*>(.*?)<'.format(sectionname),
html)
+
fr'(?s)<td>{sectionname}</td>.*?<a[^<>]*>(.*?)<',
html)
if section:
result += [
','.join(name.split(',')[:-1])
@@ -5618,7 +5618,7 @@
result = ConorAnalyzer.findnames(self, html)
for sectionname in ['Име на лице', 'Вариант на име на лице']:
section = self.findbyre(
-
r'(?s)<td>{}</td>.*?<a[^<>]*>(.*?)<'.format(sectionname),
html)
+
fr'(?s)<td>{sectionname}</td>.*?<a[^<>]*>(.*?)<',
html)
if section:
result += [
','.join(name.split(',')[:-1])
@@ -5667,7 +5667,7 @@
result = ConorAnalyzer.findnames(self, html)
for sectionname in ['Лично име', 'Варијанте личног имена']:
section = self.findbyre(
-
r'(?s)<td>{}</td>.*?<a[^<>]*>(.*?)<'.format(sectionname),
html)
+
fr'(?s)<td>{sectionname}</td>.*?<a[^<>]*>(.*?)<',
html)
if section:
result += [
','.join(name.split(',')[:-1])
@@ -6188,7 +6188,7 @@
self.language = 'en'
def getvalue(self, field, html, dtype=None):
- return self.findbyre(r'<meta name="{}"
content="(.*?)"'.format(field),
+ return self.findbyre(fr'<meta name="{field}"
content="(.*?)"',
html, dtype)
def findinstanceof(self, html: str):
@@ -6597,7 +6597,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
-
r'(?s)<dt>\s*{}\s*</dt>\s*<dd>(.*?)</dd>'.format(field),
html,
+
fr'(?s)<dt>\s*{field}\s*</dt>\s*<dd>(.*?)</dd>', html,
dtype)
def findinstanceof(self, html: str):
@@ -6754,7 +6754,7 @@
def getsection(self, field, html, ntype=None):
return self.findbyre(
-
r'(?s){}</h2>\s*</div></div>(.*?)<[bp][>\s]'.format(field),
html,
+
fr'(?s){field}</h2>\s*</div></div>(.*?)<[bp][>\s]', html,
ntype)
def findlongtext(self, html: str):
@@ -6988,7 +6988,7 @@
def getsecondvalue(self, field, html, dtype=None):
section = self.findbyre(
-
r'(?s)"fieldname">(\s*{}\s*</span>.*?)</tr>'.format(field),
html)
+
fr'(?s)"fieldname">(\s*{field}\s*</span>.*?)</tr>',
html)
if section:
return self.findbyre(
r'<td.*?</td>\s*<td[^<>]*>(?:<[^<>]*>)*([^<>]*?)<',
section,
@@ -7138,7 +7138,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
-
r'(?s)>{}</span><span[^<>]*>(?:<[^<>]*>)?([^<>]*)</'.format(field),
+
fr'(?s)>{field}</span><span[^<>]*>(?:<[^<>]*>)?([^<>]*)</',
html, dtype)
def getvalues(self, field, html, dtype=None, link=False) -> List[str]:
@@ -9056,7 +9056,7 @@
self.language = 'en'
def getvalue(self, field, html, dtype=None):
- return
self.findbyre(r'<strong>{}:</strong>(.*?)</td>'.format(field),
+ return
self.findbyre(fr'<strong>{field}:</strong>(.*?)</td>',
html, dtype)
def getvalues(self, field, html, dtype=None) -> List[str]:
@@ -9413,7 +9413,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
-
r'(?s)<strong>{}:</strong></td>\s*<td>(.*?)</td>'.format(field),
+
fr'(?s)<strong>{field}:</strong></td>\s*<td>(.*?)</td>',
html, dtype)
def findnames(self, html) -> List[str]:
@@ -10113,7 +10113,7 @@
self.language = 'en'
def getvalue(self, field, html, dtype=None):
- return
self.findbyre(r'(?s)</i>{}.*?(<ul.*?)</ul>'.format(field), html,
+ return self.findbyre(fr'(?s)</i>{field}.*?(<ul.*?)</ul>',
html,
dtype)
def getvalues(self, field, html, dtype=None) -> List[str]:
@@ -10736,7 +10736,7 @@
def findnames(self, html) -> List[str]:
return [
-
self.findbyre(r'href="[^"]*/{}/[^"]*">(.*?)<'.format(self.id),
+
self.findbyre(fr'href="[^"]*/{self.id}/[^"]*">(.*?)<',
html),
self.findbyre(r'<title>([^<>\|]*)', html)
]
@@ -10973,7 +10973,7 @@
return html.replace(' ', ' ')
def getvalue(self, field, html, dtype=None):
- return
self.findbyre(r'>{}:\s*(?:<[^<>]*>)*([^<>]+)<'.format(field),
+ return
self.findbyre(fr'>{field}:\s*(?:<[^<>]*>)*([^<>]+)<',
html, dtype)
def findinstanceof(self, html: str):
@@ -11666,7 +11666,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
-
r'(?s)<b>{}:</b>(?:\s|<[^<>]*>)*([^<>]+)'.format(field),
html,
+
fr'(?s)<b>{field}:</b>(?:\s|<[^<>]*>)*([^<>]+)',
html,
dtype)
def findinstanceof(self, html: str):
@@ -11956,7 +11956,7 @@
if alt is None:
alt = []
return self.findbyre(
-
r'(?s)<bdi>{}</bdi></strong>(.*?)</p>'.format(field),
html, dtype,
+ fr'(?s)<bdi>{field}</bdi></strong>(.*?)</p>',
html, dtype,
alt=alt)
def findnames(self, html) -> List[str]:
@@ -12013,7 +12013,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
- r'(?s)<td id="{}"
title="([^"<>]+)">'.format(field), html, dtype)
+ fr'(?s)<td id="{field}"
title="([^"<>]+)">', html, dtype)
def getvalues(self, field, html, dtype=None) -> List[str]:
section = self.getvalue(field, html)
@@ -12068,7 +12068,7 @@
self.language = 'nl'
def getvalue(self, field, html, category=None):
- return
self.findbyre(r'<dt>{}</dt><dd>(.*?)<'.format(field), html,
+ return self.findbyre(fr'<dt>{field}</dt><dd>(.*?)<',
html,
category)
def findnames(self, html) -> List[str]:
@@ -12575,7 +12575,7 @@
self.language = 'en'
def getvalue(self, field, html, dtype=None):
- return
self.findbyre(r'<dt>{}:</dt><dd>(.*?)</dd>'.format(field),
html,
+ return
self.findbyre(fr'<dt>{field}:</dt><dd>(.*?)</dd>', html,
dtype)
def findnames(self, html) -> List[str]:
@@ -12863,7 +12863,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
-
r'<SPAN[^<>]*>{}:\s*</SPAN>(?:\s|<[^<>]*>)*([^<>]*)'.format(field),
+
fr'<SPAN[^<>]*>{field}:\s*</SPAN>(?:\s|<[^<>]*>)*([^<>]*)',
html, dtype)
def getvalues(self, field, html, dtype=None) -> List[str]:
@@ -14271,7 +14271,7 @@
def getvalue(self, field, html, dtype=None, alt=None):
return self.findbyre(
-
'(?s)<strong>{}</strong><br>(.*?)</p>'.format(field),
html, dtype,
+ f'(?s)<strong>{field}</strong><br>(.*?)</p>',
html, dtype,
alt=alt)
def getvalues(self, field, html, dtype=None, alt=None) -> List[str]:
@@ -14343,12 +14343,12 @@
def getvalue(self, field, html, dtype=None, alt=None):
return self.findbyre(
-
'(?s)<th>{}</th><td>(?:<a[^<>]*>)?(.*?)<'.format(field),
html,
+
f'(?s)<th>{field}</th><td>(?:<a[^<>]*>)?(.*?)<',
html,
dtype, alt=alt)
def getvalues(self, field, html, dtype=None, alt=None) -> List[str]:
return self.findallbyre(
-
'(?s)<th>{}</th><td>(?:<a[^<>]*>)?(.*?)<'.format(field),
html,
+
f'(?s)<th>{field}</th><td>(?:<a[^<>]*>)?(.*?)<',
html,
dtype, alt=alt)
def findinstanceof(self, html: str):
@@ -14632,7 +14632,7 @@
self.language = 'pl'
def getvalue(self, field, letter, html, dtype=None):
- row =
self.findbyre(r'(<tr><td[^<>]*>{}\s*<.*?</tr>)'.format(field),
+ row =
self.findbyre(fr'(<tr><td[^<>]*>{field}\s*<.*?</tr>)',
html)
if row:
return
self.findbyre(r'<I>\s*{}\s*</TT></I>(.*?)<'.fomat(letter),
@@ -14642,10 +14642,10 @@
def getvalues(self, field, letter, html, dtype=None) -> List[str]:
result = []
rows = self.findallbyre(
-
r'(<tr><td[^<>]*>{}\s*<.*?</tr>)'.format(field), html)
+ fr'(<tr><td[^<>]*>{field}\s*<.*?</tr>)',
html)
for row in rows:
result += self.findallbyre(
-
r'<I>\s*{}\s*</TT></I>(.*?)<'.format(letter), row, dtype)
+ fr'<I>\s*{letter}\s*</TT></I>(.*?)<', row,
dtype)
return result
def findinstanceof(self, html: str):
@@ -14705,7 +14705,7 @@
self.escapehtml = True
def getvalue(self, field, html, dtype=None):
- return
self.findbyre(r'(?s)<b>{}</b>\s*:\s*([^<>]*)'.format(field),
+ return
self.findbyre(fr'(?s)<b>{field}</b>\s*:\s*([^<>]*)',
html, dtype)
def getvalues(self, field, html, dtype=None) -> List[str]:
@@ -14885,7 +14885,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
-
r'(?s)>{}:</td>\s*<td[^<>]*>(.*?)</td>'.format(field),
html, dtype)
+
fr'(?s)>{field}:</td>\s*<td[^<>]*>(.*?)</td>', html,
dtype)
def findinstanceof(self, html: str):
return 'Q5'
@@ -14965,7 +14965,7 @@
if alt is None:
alt = []
return self.findbyre(
-
r'(?s)<h3>\s*{}\s*</h3>\s*<div[^<>]*>(.*?)</div>'.format(field),
+
fr'(?s)<h3>\s*{field}\s*</h3>\s*<div[^<>]*>(.*?)</div>',
html, dtype, alt=alt)
def getvalues(self, field, html, dtype=None, alt=None) -> List[str]:
@@ -16408,7 +16408,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
-
'(?s)<strong>{}</strong>.*?<td[^<>]*>(.*?)</td>'.format(field),
+
f'(?s)<strong>{field}</strong>.*?<td[^<>]*>(.*?)</td>',
html, dtype)
def getvalues(self, field, html, dtype=None) -> List[str]:
@@ -16639,7 +16639,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
-
r'(?s)<h3>{}</h3>\s*<div>(.*?)</div>'.format(field), html,
dtype)
+ fr'(?s)<h3>{field}</h3>\s*<div>(.*?)</div>',
html, dtype)
def instanceof(self, html: str):
return self.findbyre('Category', html, 'instanceof')
@@ -16837,7 +16837,7 @@
def getvalue(self, field, html, dtype=None):
return self.findbyre(
- r'<meta property=(?:\w+:)?{}"
content="(.*?)"'.format(field), html,
+ fr'<meta property=(?:\w+:)?{field}"
content="(.*?)"', html,
dtype)
def findinstanceof(self, html: str):
diff --git a/scripts/maintenance/unidata.py b/scripts/maintenance/unidata.py
old mode 100644
new mode 100755
index 2d6b03a..29c3444
--- a/scripts/maintenance/unidata.py
+++ b/scripts/maintenance/unidata.py
@@ -14,16 +14,16 @@
#
# Distributed under the terms of the MIT license.
#
-from sys import maxunicode
-from re import findall
from json import dump, load
from queue import Queue
+from re import findall
+from sys import maxunicode
from threading import Thread
-from scripts.maintenance.wikimedia_sites import families_list
-from pywikibot.family import Family
from pywikibot import Site
from pywikibot.comms.http import session
+from pywikibot.family import Family
+from scripts.maintenance.wikimedia_sites import families_list
NUMBER_OF_THREADS = 26
@@ -133,7 +133,7 @@
def load_json(path):
"""Load data from file."""
try:
- with open(path, 'r', encoding='utf8') as f:
+ with open(path, encoding='utf8') as f:
return load(f)
except OSError:
print('File not found:', path) # noqa: T001, T201
diff --git a/tests/file_tests.py b/tests/file_tests.py
index 0f59774..adf1d92 100755
--- a/tests/file_tests.py
+++ b/tests/file_tests.py
@@ -12,6 +12,7 @@
from itertools import chain
import pywikibot
+from pywikibot import pagegenerators
from pywikibot.exceptions import (
Error,
NoPageError,
@@ -19,7 +20,6 @@
PageRelatedError,
UserRightsError,
)
-from pywikibot import pagegenerators
from tests import join_images_path
from tests.aspects import TestCase
diff --git a/tests/site_decorators_tests.py b/tests/site_decorators_tests.py
index dfcfd3f..e556c45 100755
--- a/tests/site_decorators_tests.py
+++ b/tests/site_decorators_tests.py
@@ -10,7 +10,7 @@
from pywikibot.exceptions import UserRightsError
from pywikibot.site._decorators import must_be, need_right, need_version
from pywikibot.tools import deprecated
-from tests.aspects import TestCase, DeprecationTestCase
+from tests.aspects import DeprecationTestCase, TestCase
class TestMustBe(TestCase):
diff --git a/tests/sparql_tests.py b/tests/sparql_tests.py
index a14f4f0..25f5aab 100755
--- a/tests/sparql_tests.py
+++ b/tests/sparql_tests.py
@@ -12,9 +12,9 @@
import pywikibot
import pywikibot.data.sparql as sparql
+from pywikibot.exceptions import NoUsernameError
from tests.aspects import TestCase, WikidataTestCase
from tests.utils import skipping
-from pywikibot.exceptions import NoUsernameError
# See:
https://www.w3.org/TR/2013/REC-sparql11-results-json-20130321/
diff --git a/tests/utils.py b/tests/utils.py
index 8c0ce06..2830ea4 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -20,10 +20,9 @@
from pywikibot.data.api import Request as _original_Request
from pywikibot.exceptions import APIError
from pywikibot.login import LoginStatus
-from pywikibot.tools.collections import EMPTY_DEFAULT
from pywikibot.site import Namespace
from pywikibot.tools import PYTHON_VERSION
-
+from pywikibot.tools.collections import EMPTY_DEFAULT
from tests import _pwb_py
@@ -476,7 +475,7 @@
:param command: executable to run and arguments to use
"""
if PYTHON_VERSION < (3, 7):
- command.insert(1, '-W ignore::FutureWarning:pywikibot:110')
+ command.insert(1, '-W ignore::FutureWarning:pywikibot:111')
env = os.environ.copy()
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/979482
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: I180a6a9d20e9a85730e2976e28d1359be17327a1
Gerrit-Change-Number: 979482
Gerrit-PatchSet: 2
Gerrit-Owner: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged