Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-95813: Improve HTMLParser from the view of inheritance #95874

Merged
merged 3 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/html/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self, *, convert_charrefs=True):
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()

Expand All @@ -98,7 +99,7 @@ def reset(self):
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.
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_htmlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pprint
import unittest

from unittest.mock import patch


class EventCollector(html.parser.HTMLParser):

Expand Down Expand Up @@ -787,5 +789,17 @@ def test_weird_chars_in_unquoted_attribute_values(self):
('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()