jenkins-bot submitted this change.
[IMPR] Deprecate textlib.unescape
This function is unused by pywikibot and python 3.4+ provides it...
https://docs.python.org/3/library/html.html#html.unescape
Change-Id: Ie4664ea814d735a10799be2c4576b054eb960798
---
M pywikibot/textlib.py
M tests/textlib_tests.py
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 75ae916..2ee62d1 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -11,6 +11,7 @@
# Distributed under the terms of the MIT license.
#
import datetime
+import html
import re
from collections.abc import Sequence
@@ -147,15 +148,10 @@
return phrase
+@deprecated('html.unescape', since='20210405', future_warning=True)
def unescape(s: str) -> str:
"""Replace escaped HTML-special characters by their originals."""
- if '&' in s:
- s = s.replace('<', '<')
- s = s.replace('>', '>')
- s = s.replace(''', "'")
- s = s.replace('"', '"')
- s = s.replace('&', '&') # Must be last
- return s
+ return html.unescape(s)
class _MultiTemplateMatchBuilder:
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 8b537b3..dadc2a3 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -1639,6 +1639,10 @@
self.assertEqual(set(lang_links), self.sites_set - {self.site})
+UNESCAPE_WARNING_MSG = (r'.*pywikibot\.textlib\.unescape .*'
+ r'is deprecated for .*; use html.unescape')
+
+
class TestUnescape(TestCase):
"""Test to verify that unescaping HTML chars are correctly done."""
@@ -1647,8 +1651,9 @@
def test_unescape(self):
"""Test unescaping HTML chars."""
- self.assertEqual(textlib.unescape('!23<>'"&&'),
- '!23<>\'"&&')
+ with suppress_warnings(UNESCAPE_WARNING_MSG, category=FutureWarning):
+ self.assertEqual(textlib.unescape('!23<>'"&&'),
+ '!23<>\'"&&')
class TestExtractSections(DefaultDrySiteTestCase):
To view, visit change 677042. To unsubscribe, or for help writing mail filters, visit settings.