]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-95813: Improve HTMLParser from the view of inheritance (#95874)
authorDong-hee Na <donghee.na@python.org>
Thu, 18 Aug 2022 11:16:33 +0000 (20:16 +0900)
committerGitHub <noreply@github.com>
Thu, 18 Aug 2022 11:16:33 +0000 (13:16 +0200)
* gh-95813: Improve HTMLParser from the view of inheritance

* gh-95813: Add unittest

* Address code review

Lib/html/parser.py
Lib/test/test_htmlparser.py

index bef0f4fe4bf776c34aac57ab9bbbce6d3ab238f5..13c95c34e505c8958444799fbafa83e774669fb1 100644 (file)
@@ -89,6 +89,7 @@ class HTMLParser(_markupbase.ParserBase):
         If convert_charrefs is True (the default), all character references
         are automatically converted to the corresponding Unicode characters.
         """
+        super().__init__()
         self.convert_charrefs = convert_charrefs
         self.reset()
 
@@ -98,7 +99,7 @@ class HTMLParser(_markupbase.ParserBase):
         self.lasttag = '???'
         self.interesting = interesting_normal
         self.cdata_elem = None
-        _markupbase.ParserBase.reset(self)
+        super().reset()
 
     def feed(self, data):
         r"""Feed data to the parser.
index 12917755a56017e31e6a5ba2c241bd01673e823a..b42a611c62c0aa1a2d47c95d76b958d2b7f10770 100644 (file)
@@ -4,6 +4,8 @@ import html.parser
 import pprint
 import unittest
 
+from unittest.mock import patch
+
 
 class EventCollector(html.parser.HTMLParser):
 
@@ -787,5 +789,17 @@ class AttributesTestCase(TestCaseBase):
                             ('starttag', 'form',
                                 [('action', 'bogus|&#()value')])])
 
+
+class TestInheritance(unittest.TestCase):
+
+    @patch("_markupbase.ParserBase.__init__")
+    @patch("_markupbase.ParserBase.reset")
+    def test_base_class_methods_called(self, super_reset_method, super_init_method):
+        with patch('_markupbase.ParserBase') as parser_base:
+            EventCollector()
+            super_init_method.assert_called_once()
+            super_reset_method.assert_called_once()
+
+
 if __name__ == "__main__":
     unittest.main()