jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1165466?usp=email )
Change subject: [IMPR] rename NON_LATIN_DIGITS to NON_ASCII_DIGITS
......................................................................
[IMPR] rename NON_LATIN_DIGITS to NON_ASCII_DIGITS
- also rename textlib.to_latin_digits to to_ascii_digits
- update any occurrence
- deprecate the old variant
This patch is inspired by T398146#10958283
Change-Id: I43b11df3f2141a2f571a705692d3dab28a93ef43
---
M HISTORY.rst
M pywikibot/cosmetic_changes.py
M pywikibot/date.py
M pywikibot/textlib.py
M pywikibot/userinterfaces/transliteration.py
M scripts/archivebot.py
M tests/textlib_tests.py
M tests/ui_tests.py
8 files changed, 59 insertions(+), 46 deletions(-)
Approvals:
jenkins-bot: Verified
Huji: Looks good to me, approved
diff --git a/HISTORY.rst b/HISTORY.rst
index 3b45a1d..f58f9ec 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -90,7 +90,7 @@
* ``APISite.article_path`` was removed. :attr:`APISite.articlepath
<pywikibot.site._apisite.APISite.articlepath>` can be used instead.
* ``fix_digits`` method of :class:`textlib.TimeStripper` was removed;
- :func:`textlib.to_latin_digits` can be used instead.
+ :func:`textlib.to_ascii_digits` can be used instead.
* :mod:`textlib`.tzoneFixedOffset class was removed in favour of
:class:`time.TZoneFixedOffse<pywikibot.time.TZoneFixedOffset>`.
* A boolean *watch* parameter in :meth:`page.BasePage.save` is desupported.
@@ -929,9 +929,9 @@
**Improvements**
* i18n updates for date.py
-* Add number transliteration of 'lo', 'ml', 'pa', 'te' to NON_LATIN_DIGITS
+* Add number transliteration of 'lo', 'ml', 'pa', 'te' to NON_ASCII_DIGITS
* Detect range blocks with Page.is_blocked() method (:phab:`T301282`)
-* to_latin_digits() function was added to textlib as counterpart of
to_local_digits() function
+* to_ascii_digits() function was added to textlib as counterpart of
to_local_digits() function
* api.Request.submit now handles search-title-disabled and
search-text-disabled API Errors
* A show_diff parameter was added to Page.put() and Page.change_category()
* Allow categories when saving IndexPage (:phab:`T299806`)
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index b78b8fe..ed1380b 100644
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -68,7 +68,7 @@
from pywikibot.site import Namespace
from pywikibot.tools import first_lower, first_upper
from pywikibot.tools.chars import url2string
-from pywikibot.userinterfaces.transliteration import NON_LATIN_DIGITS
+from pywikibot.userinterfaces.transliteration import NON_ASCII_DIGITS
try:
@@ -1031,10 +1031,10 @@
'syntaxhighlight',
]
- digits = NON_LATIN_DIGITS['fa']
+ digits = NON_ASCII_DIGITS['fa']
faChrs = 'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیةيك' + digits
- # not to let bot edits in latin content
+ # not to let bot edits in ascii numerals content
exceptions.append(re.compile(f'[^{faChrs}] *?"*? *?, *?[^{faChrs}]'))
text = textlib.replaceExcept(text, ',', '،', exceptions,
site=self.site)
diff --git a/pywikibot/date.py b/pywikibot/date.py
index e6b4eae..9c2a01e 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -26,7 +26,7 @@
)
from pywikibot.site import BaseSite
from pywikibot.tools import deprecate_arg, first_lower, first_upper
-from pywikibot.userinterfaces.transliteration import NON_LATIN_DIGITS
+from pywikibot.userinterfaces.transliteration import NON_ASCII_DIGITS
if TYPE_CHECKING:
@@ -288,27 +288,27 @@
# Helper for KN: digits representation
-_knDigits = NON_LATIN_DIGITS['kn']
+_knDigits = NON_ASCII_DIGITS['kn']
_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']
+_faDigits = NON_ASCII_DIGITS['fa']
_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']
+_hiDigits = NON_ASCII_DIGITS['hi']
_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']
+_bnDigits = NON_ASCII_DIGITS['bn']
_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']
+_guDigits = NON_ASCII_DIGITS['gu']
_guDigitsToLocal = {ord(str(i)): _guDigits[i] for i in range(10)}
_guLocalToDigits = {ord(_guDigits[i]): str(i) for i in range(10)}
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 039bc25..5d48567 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -24,12 +24,13 @@
from pywikibot.family import Family
from pywikibot.time import TZoneFixedOffset
from pywikibot.tools import (
+ ModuleDeprecationWrapper,
deprecated,
deprecated_args,
first_lower,
first_upper,
)
-from pywikibot.userinterfaces.transliteration import NON_LATIN_DIGITS
+from pywikibot.userinterfaces.transliteration import NON_ASCII_DIGITS
try:
@@ -111,10 +112,11 @@
def to_local_digits(phrase: str | int, lang: str) -> str:
- """Change Latin digits based on language to localized version.
+ """Change ASCII digits based on language to localized version.
- Be aware that this function only works for several languages, and that it
- returns an unchanged string if an unsupported language is given.
+ .. attention:: Be aware that this function only works for several
+ languages, and that it returns an unchanged string if an
+ unsupported language is given.
.. versionchanged:: 7.5
always return a string even `phrase` is an int.
@@ -123,7 +125,7 @@
:param lang: language code
:return: The localized version
"""
- digits = NON_LATIN_DIGITS.get(lang)
+ digits = NON_ASCII_DIGITS.get(lang)
phrase = str(phrase)
if digits:
trans = str.maketrans('0123456789', digits)
@@ -131,24 +133,26 @@
return phrase
-def to_latin_digits(phrase: str,
+def to_ascii_digits(phrase: str,
langs: SequenceType[str] | str | None = None) -> str:
- """Change non-latin digits to latin digits.
+ """Change non-ascii digits to ascii digits.
.. versionadded:: 7.0
+ .. versionchanged:: 10.3
+ this function was renamed from to_latin_digits.
- :param phrase: The phrase to convert to latin numerical.
+ :param phrase: The phrase to convert to ascii numerical.
:param langs: Language codes. If langs parameter is None, use all
known languages to convert.
- :return: The string with latin digits
+ :return: The string with ascii digits
"""
if langs is None:
- langs = NON_LATIN_DIGITS.keys()
+ langs = NON_ASCII_DIGITS.keys()
elif isinstance(langs, str):
langs = [langs]
- digits = [NON_LATIN_DIGITS[key] for key in langs
- if key in NON_LATIN_DIGITS]
+ digits = [NON_ASCII_DIGITS[key] for key in langs
+ if key in NON_ASCII_DIGITS]
if digits:
trans = str.maketrans(''.join(digits), '0123456789' * len(digits))
phrase = phrase.translate(trans)
@@ -2214,7 +2218,7 @@
line = removeDisabledParts(line)
line = removeHTMLParts(line)
- line = to_latin_digits(line)
+ line = to_ascii_digits(line)
for pat in self.patterns:
line, match_obj = self._last_match_and_replace(line, pat)
if match_obj:
@@ -2269,3 +2273,7 @@
timestamp = None
return timestamp
+
+
+wrapper = ModuleDeprecationWrapper(__name__)
+wrapper.add_deprecated_attr('to_latin_digits', to_ascii_digits, since='10.3.0')
diff --git a/pywikibot/userinterfaces/transliteration.py
b/pywikibot/userinterfaces/transliteration.py
index 6fdf6f1..5719bd0 100644
--- a/pywikibot/userinterfaces/transliteration.py
+++ b/pywikibot/userinterfaces/transliteration.py
@@ -1,6 +1,6 @@
"""Module to transliterate text."""
#
-# (C) Pywikibot team, 2006-2024
+# (C) Pywikibot team, 2006-2025
#
# Distributed under the terms of the MIT license.
#
@@ -9,8 +9,8 @@
from pywikibot.tools import ModuleDeprecationWrapper, deprecate_arg
-#: Non latin digits used by the framework
-NON_LATIN_DIGITS = {
+#: Non ascii digits used by the framework
+NON_ASCII_DIGITS = {
'bn': '০১২৩৪৫৬৭৮৯',
'ckb': '٠١٢٣٤٥٦٧٨٩',
'fa': '۰۱۲۳۴۵۶۷۸۹',
@@ -1096,7 +1096,7 @@
'𐬳': 'shye', '𐬴': 'sshe', '𐬵': 'he',
}
-for digits in NON_LATIN_DIGITS.values():
+for digits in NON_ASCII_DIGITS.values():
_trans.update({char: str(i) for i, char in enumerate(digits)})
@@ -1154,3 +1154,6 @@
wrapper = ModuleDeprecationWrapper(__name__)
wrapper.add_deprecated_attr('transliterator', Transliterator, since='9.0.0')
+wrapper.add_deprecated_attr('NON_LATIN_DIGITS', NON_ASCII_DIGITS,
+ replacement_name='NON_ASCII_DIGITS',
+ since='10.3.0')
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 3b018ed..a199175 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -61,16 +61,16 @@
the page being archived.
Variables below can be used in the value for "archive" in the template
-above; numbers are **latin** digits. Alternatively you may use
+above; numbers are **ascii** digits. Alternatively you may use
**localized** digits. This is only available for a few site languages.
-Refer :attr:`NON_LATIN_DIGITS
-<userinterfaces.transliteration.NON_LATIN_DIGITS>` whether there is a
+Refer :attr:`NON_ASCII_DIGITS
+<userinterfaces.transliteration.NON_ASCII_DIGITS>` whether there is a
localized one.
.. list-table::
:header-rows: 1
- * - latin
+ * - ascii
- localized
- Description
* - %(counter)d
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 9ab1ff1..6c61a3b 100755
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -990,7 +990,7 @@
net = False
def test_to_local(self) -> None:
- """Test converting Latin digits to local digits."""
+ """Test converting ASCII digits to local digits."""
self.assertEqual(textlib.to_local_digits(299792458, 'en'), '299792458')
self.assertEqual(
textlib.to_local_digits(299792458, 'fa'), '۲۹۹۷۹۲۴۵۸')
@@ -1001,20 +1001,20 @@
textlib.to_local_digits('299792458', 'km'), '២៩៩៧៩២៤៥៨')
def test_to_latin(self) -> None:
- """Test converting local digits to Latin digits."""
- self.assertEqual(textlib.to_latin_digits('299792458'), '299792458')
+ """Test converting local digits to ASCII digits."""
+ self.assertEqual(textlib.to_ascii_digits('299792458'), '299792458')
self.assertEqual(
- textlib.to_latin_digits('۲۹۹۷۹۲۴۵۸', 'fa'), '299792458')
+ textlib.to_ascii_digits('۲۹۹۷۹۲۴۵۸', 'fa'), '299792458')
self.assertEqual(
- textlib.to_latin_digits('۲۹۹۷۹۲۴۵۸ flash'), '299792458 flash')
+ textlib.to_ascii_digits('۲۹۹۷۹۲۴۵۸ flash'), '299792458 flash')
self.assertEqual(
- textlib.to_latin_digits('២៩៩៧៩២៤៥៨', 'km'), '299792458')
+ textlib.to_ascii_digits('២៩៩៧៩២៤៥៨', 'km'), '299792458')
self.assertEqual(
- textlib.to_latin_digits('២៩៩៧៩២៤៥៨'), '299792458')
+ textlib.to_ascii_digits('២៩៩៧៩២៤៥៨'), '299792458')
self.assertEqual(
- textlib.to_latin_digits('២៩៩៧៩២៤៥៨', ['km', 'en']), '299792458')
+ textlib.to_ascii_digits('២៩៩៧៩២៤៥៨', ['km', 'en']), '299792458')
self.assertEqual(
- textlib.to_latin_digits('២៩៩៧៩២៤៥៨', ['en']), '២៩៩៧៩២៤៥៨')
+ textlib.to_ascii_digits('២៩៩៧៩២៤៥៨', ['en']), '២៩៩៧៩២៤៥៨')
class TestReplaceExcept(DefaultDrySiteTestCase):
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index a7c1b4e..8c29d34 100755
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -31,7 +31,7 @@
terminal_interface_unix,
terminal_interface_win32,
)
-from pywikibot.userinterfaces.transliteration import NON_LATIN_DIGITS, _trans
+from pywikibot.userinterfaces.transliteration import NON_ASCII_DIGITS, _trans
from tests.aspects import TestCase, TestCaseBase
@@ -359,11 +359,13 @@
net = False
- def test_latin_digits(self) -> None:
- """Test that non latin digits are in transliteration table."""
- for lang, digits in NON_LATIN_DIGITS.items():
+ def test_ascii_digits(self) -> None:
+ """Test that non ascii digits are in transliteration table."""
+ for lang, digits in NON_ASCII_DIGITS.items():
with self.subTest(lang=lang):
for char in digits:
+ self.assertTrue(char.isdigit())
+ self.assertFalse(char.isascii())
self.assertIn(char, _trans,
f'{char!r} not in transliteration table')
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1165466?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I43b11df3f2141a2f571a705692d3dab28a93ef43
Gerrit-Change-Number: 1165466
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Huji <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]