-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-95813: Improve HTMLParser from the view of inheritance #95874
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
Conversation
corona10
commented
Aug 11, 2022
•
edited by bedevere-bot
Loading
edited by bedevere-bot
- Issue: Class HTMLParser may not be initialized properly as method ParserBase.__init__ is not called from its __init__ method #95813
@corona10, thanks for the PR! |
Updated! Without patch:
|
diff --git a/Lib/_markupbase.py b/Lib/_markupbase.py
index 3ad7e27996..f8b2b901b9 100644
--- a/Lib/_markupbase.py
+++ b/Lib/_markupbase.py
@@ -7,6 +7,7 @@
import re
+from abc import ABCMeta, abstractmethod
_declname_match = re.compile(r'[a-zA-Z][-_.a-zA-Z0-9]*\s*').match
_declstringlit_match = re.compile(r'(\'[^\']*\'|"[^"]*")\s*').match
_commentclose = re.compile(r'--\s*>')
@@ -20,7 +21,7 @@
del re
-class ParserBase:
+class ParserBase(metaclass=ABCMeta):
"""Parser base class which provides some common support methods used
by the SGML/HTML and XHTML parsers."""
@@ -391,6 +392,6 @@ def _scan_name(self, i, declstartpos):
"expected name token at %r" % rawdata[declstartpos:declstartpos+20]
)
- # To be overridden -- handlers for unknown objects
+ @abstractmethod
def unknown_decl(self, data):
pass One more thing, what about update ParserBase as abstract class? |
@ezio-melotti gentle ping |
When you're done making the requested changes, leave the comment: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ezio-melotti
I have made the requested changes; please review again.
Thanks for the PR!
We could, but I don't think it's necessary. |
…on#95874) * pythongh-95813: Improve HTMLParser from the view of inheritance * pythongh-95813: Add unittest * Address code review