jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612606 )
Change subject: [4.0] remove Python 2 code parts of date.py
......................................................................
[4.0] remove Python 2 code parts of date.py
Change-Id: I5c54e99ee8718336bd1d6ab1b630274326cff27b
---
M pywikibot/date.py
1 file changed, 29 insertions(+), 36 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/date.py b/pywikibot/date.py
index 9c97756..c01700f 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -5,17 +5,17 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import calendar
-from collections import defaultdict
import datetime
import re
+
+from collections import defaultdict
+from contextlib import suppress
from string import digits as _decimalDigits # noqa: N812
from pywikibot import Site
from pywikibot.textlib import NON_LATIN_DIGITS
-from pywikibot.tools import first_lower, first_upper, deprecated, UnicodeType
+from pywikibot.tools import first_lower, first_upper, deprecated
#
# Different collections of well known formats
@@ -54,7 +54,7 @@
When the 2nd function evaluates to true, the 1st function is used.
"""
- if isinstance(value, UnicodeType):
+ if isinstance(value, str):
# Try all functions, and test result against predicates
for func, pred in tuplst:
try:
@@ -209,10 +209,7 @@
formats['MonthName']['en']('anything else') => raise ValueError
"""
- if isinstance(value, UnicodeType):
- return lst.index(value) + 1
- else:
- return lst[value - 1]
+ return lst.index(value) + 1 if isinstance(value, str) else lst[value - 1]
def dh_singVal(value, match):
@@ -226,7 +223,7 @@
formats['CurrEvents']['en'](ind) => 'Current Events'
formats['CurrEvents']['en']('Current Events') => ind
"""
- if isinstance(value, UnicodeType):
+ if isinstance(value, str):
if value == match:
return ind
elif value == ind:
@@ -254,33 +251,33 @@
# Helper for KN: digits representation
_knDigits = NON_LATIN_DIGITS['kn']
-_knDigitsToLocal = {ord(UnicodeType(i)): _knDigits[i] for i in range(10)}
-_knLocalToDigits = {ord(_knDigits[i]): UnicodeType(i) for i in range(10)}
+_knDigitsToLocal = {ord(str(i)): _knDigits[i] for i in range(10)}
+_knLocalToDigits = {ord(_knDigits[i]): str(i) for i in range(10)}
# Helper for Urdu/Persian languages
_faDigits = NON_LATIN_DIGITS['fa']
-_faDigitsToLocal = {ord(UnicodeType(i)): _faDigits[i] for i in range(10)}
-_faLocalToDigits = {ord(_faDigits[i]): UnicodeType(i) for i in range(10)}
+_faDigitsToLocal = {ord(str(i)): _faDigits[i] for i in range(10)}
+_faLocalToDigits = {ord(_faDigits[i]): str(i) for i in range(10)}
# Helper for HI:, MR:
_hiDigits = NON_LATIN_DIGITS['hi']
-_hiDigitsToLocal = {ord(UnicodeType(i)): _hiDigits[i] for i in range(10)}
-_hiLocalToDigits = {ord(_hiDigits[i]): UnicodeType(i) for i in range(10)}
+_hiDigitsToLocal = {ord(str(i)): _hiDigits[i] for i in range(10)}
+_hiLocalToDigits = {ord(_hiDigits[i]): str(i) for i in range(10)}
# Helper for BN:
_bnDigits = NON_LATIN_DIGITS['bn']
-_bnDigitsToLocal = {ord(UnicodeType(i)): _bnDigits[i] for i in range(10)}
-_bnLocalToDigits = {ord(_bnDigits[i]): UnicodeType(i) for i in range(10)}
+_bnDigitsToLocal = {ord(str(i)): _bnDigits[i] for i in range(10)}
+_bnLocalToDigits = {ord(_bnDigits[i]): str(i) for i in range(10)}
# Helper for GU:
_guDigits = NON_LATIN_DIGITS['gu']
-_guDigitsToLocal = {ord(UnicodeType(i)): _guDigits[i] for i in range(10)}
-_guLocalToDigits = {ord(_guDigits[i]): UnicodeType(i) for i in range(10)}
+_guDigitsToLocal = {ord(str(i)): _guDigits[i] for i in range(10)}
+_guLocalToDigits = {ord(_guDigits[i]): str(i) for i in range(10)}
def intToLocalDigitsStr(value, digitsToLocalDict):
"""Encode an integer value into a textual form."""
- return UnicodeType(value).translate(digitsToLocalDict)
+ return str(value).translate(digitsToLocalDict)
def localDigitsStrToInt(value, digitsToLocalDict, localToDigitsDict):
@@ -318,7 +315,7 @@
# %% is a %
'%': '%',
# %d is a decimal
- 'd': (_decimalDigits, UnicodeType, int),
+ 'd': (_decimalDigits, str, int),
# %R is a roman numeral. This allows for only the simplest linear
# conversions based on a list of numbers
'R': ('IVX', intToRomanNum, romanNumToInt),
@@ -343,7 +340,7 @@
lambda v: localDigitsStrToInt(v, _guDigitsToLocal,
_guLocalToDigits)),
# %T is a year in TH: -- all years are shifted: 2005 => 'พ.ศ. 2548'
- 'T': (_decimalDigits, lambda v: UnicodeType(v + 543),
+ 'T': (_decimalDigits, lambda v: str(v + 543),
lambda v: int(v) - 543),
}
@@ -375,7 +372,7 @@
and (len(s) == 2 or s[1] in _decimalDigits)):
# Must match a "%2d" or "%d" style
dec = _digitDecoders[s[-1]]
- if isinstance(dec, UnicodeType):
+ if isinstance(dec, str):
# Special case for strings that are replaced instead of
# decoded
assert len(s) < 3, (
@@ -436,7 +433,7 @@
"""
compPattern, strPattern, decoders = escapePattern2(pattern)
- if isinstance(value, UnicodeType):
+ if isinstance(value, str):
m = compPattern.match(value)
if m:
# decode each found value using provided decoder
@@ -444,7 +441,7 @@
for i, decoder in enumerate(decoders)]
decValue = decf(values)
- assert not isinstance(decValue, UnicodeType), \
+ assert not isinstance(decValue, str), \
'Decoder must not return a string!'
# recursive call to re-encode and see if we get the original
@@ -2187,29 +2184,25 @@
@return: dictName ('YearBC', 'December', ...) and value (a year, date, ...)
@rtype: tuple
"""
- for dictName, dict in formats.items():
- try:
- year = dict[lang](title)
- return dictName, year
- except Exception:
- pass
+ for dict_name, dictionary in formats.items():
+ with suppress(Exception):
+ year = dictionary[lang](title)
+ return dict_name, year
# sometimes the title may begin with an upper case while its listed as
# lower case, or the other way around
# change case of the first character to the opposite, and try again
if ignoreFirstLetterCase:
- try:
+ with suppress(Exception):
if title[0].isupper():
title = first_lower(title)
else:
title = first_upper(title)
return getAutoFormat(lang, title, ignoreFirstLetterCase=False)
- except Exception:
- pass
return None, None
@deprecated('date.format_date', since='20190526')
-class FormatDate(object):
+class FormatDate:
"""DEPRECATED. Format a date."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612606
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: I5c54e99ee8718336bd1d6ab1b630274326cff27b
Gerrit-Change-Number: 612606
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/596481 )
Change subject: [bugfix] There are more splitlines boundaries than just "\n"
......................................................................
[bugfix] There are more splitlines boundaries than just "\n"
- test for all boundaries used by splitlines
- also remove Python 2 related code parts
Change-Id: I65b2a3df0f59c91ad3be38aefc816a5fca057dcf
---
M pywikibot/diff.py
1 file changed, 11 insertions(+), 25 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index 1bc9a20..150e5c5 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -5,28 +5,19 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import difflib
import math
-try:
- from collections.abc import Sequence
-except ImportError: # Python 2.7
- from collections import Sequence
+from collections.abc import Sequence
from difflib import _format_range_unified as format_range_unified
+from itertools import zip_longest
import pywikibot
-from pywikibot.tools import chars, deprecated_args, PY2
+from pywikibot.tools import chars, deprecated_args
from pywikibot.tools.formatter import color_format
-if not PY2:
- from itertools import zip_longest
-else:
- from itertools import izip_longest as zip_longest
-
-class Hunk(object):
+class Hunk:
"""One change hunk between a and b.
@@ -154,16 +145,14 @@
fmt = fmt if fmt else None
yield self.color_line(line2, fmt)
- def color_line(self, line, line_ref=None):
+ def color_line(self, line: str, line_ref=None):
"""Color line characters.
If line_ref is None, the whole line is colored.
If line_ref[i] is not blank, line[i] is colored.
Color depends if line starts with +/-.
- line: string
line_ref: string.
-
"""
color = line[0]
@@ -246,7 +235,7 @@
hunk.reviewed = reviewed
-class PatchManager(object):
+class PatchManager:
"""Apply patches to text_a to obtain a new text.
@@ -254,14 +243,12 @@
"""
@deprecated_args(n='context')
- def __init__(self, text_a, text_b, context=0, by_letter=False,
- replace_invisible=False):
+ def __init__(self, text_a: str, text_b: str, context=0, by_letter=False,
+ replace_invisible=False) -> None:
"""Initializer.
@param text_a: base text
- @type text_a: basestring
@param text_b: target text
- @type text_b: basestring
@param context: number of lines which are context
@type context: int
@param by_letter: if text_a and text_b are single lines, comparison can
@@ -271,10 +258,9 @@
the charnumber in brackets (e.g. <200e>).
@type replace_invisible: bool
"""
- if '\n' in text_a or '\n' in text_b or not by_letter:
- self.a = text_a.splitlines(1)
- self.b = text_b.splitlines(1)
- else:
+ self.a = text_a.splitlines(True)
+ self.b = text_b.splitlines(True)
+ if by_letter and len(self.a) <= 1 and len(self.b) <= 1:
self.a = text_a
self.b = text_b
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/596481
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: I65b2a3df0f59c91ad3be38aefc816a5fca057dcf
Gerrit-Change-Number: 596481
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/614217 )
Change subject: [FIX] Use named groupsize parameter for preloadpages
......................................................................
[FIX] Use named groupsize parameter for preloadpages
Bug: T258329
Change-Id: I5e208e5b8262969b38aa092078157fc431513e2c
---
M pywikibot/pagegenerators.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index b6eeed8..ecd7a61 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -2207,11 +2207,11 @@
if len(sites[site]) >= groupsize:
# if this site is at the groupsize, process it
group = sites.pop(site)
- yield from site.preloadpages(group, groupsize)
+ yield from site.preloadpages(group, groupsize=groupsize)
for site, pages in sites.items():
# process any leftover sites that never reached the groupsize
- yield from site.preloadpages(pages, groupsize)
+ yield from site.preloadpages(pages, groupsize=groupsize)
@deprecated_args(step='groupsize')
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/614217
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: I5e208e5b8262969b38aa092078157fc431513e2c
Gerrit-Change-Number: 614217
Gerrit-PatchSet: 1
Gerrit-Owner: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612727 )
Change subject: [4.0] Follow up on Ib0db465bfcc6a38335379
......................................................................
[4.0] Follow up on Ib0db465bfcc6a38335379
PWB doesn't also support Python 3.4. Support starts
from 3.5 and above.
Change-Id: I849289e44f0f19b5962eced5b8bf588625153252
---
M docs/index.rst
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Lokal Profil: Looks good to me, approved
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/index.rst b/docs/index.rst
index cc22a5a..3607626 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -13,7 +13,7 @@
Pywikibot is a Python library and collection of scripts that automate work on `MediaWiki <https://mediawiki.org>`_ sites.
-Pywikibot supports Python 3.4+.
+Pywikibot supports Python 3.5+.
Pywikibot and this documentation are licensed under the :ref:`MIT license <licenses-MIT>`;
manual pages on mediawiki.org are licensed under the `CC-BY-SA 3.0`_ license.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612727
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: I849289e44f0f19b5962eced5b8bf588625153252
Gerrit-Change-Number: 612727
Gerrit-PatchSet: 1
Gerrit-Owner: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <andre.costa(a)wikimedia.se>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612704 )
Change subject: [4.0] Remove py2 mention from documentation
......................................................................
[4.0] Remove py2 mention from documentation
Bug: T213287
Change-Id: Ib0db465bfcc6a383353794a141a84c96053adc1e
---
M docs/index.rst
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
D3r1ck01: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/index.rst b/docs/index.rst
index b9c0d80..cc22a5a 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -13,7 +13,7 @@
Pywikibot is a Python library and collection of scripts that automate work on `MediaWiki <https://mediawiki.org>`_ sites.
-Pywikibot supports Python 2.7.4+ and 3.4+.
+Pywikibot supports Python 3.4+.
Pywikibot and this documentation are licensed under the :ref:`MIT license <licenses-MIT>`;
manual pages on mediawiki.org are licensed under the `CC-BY-SA 3.0`_ license.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612704
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: Ib0db465bfcc6a383353794a141a84c96053adc1e
Gerrit-Change-Number: 612704
Gerrit-PatchSet: 1
Gerrit-Owner: Lokal Profil <andre.costa(a)wikimedia.se>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged