From 6f3e8dd4b39628689fe093e0f4b84b11ab7d598f Mon Sep 17 00:00:00 2001 From: Micah Najacht Date: Mon, 27 Apr 2026 01:27:05 -0500 Subject: [PATCH] gh-82665 Mention that HTMLParser.handle_starttag value can be None (GH-134312) * Specify boolean attribute behavior in parser * Tweak wording and example Co-authored-by: Serhiy Storchaka Co-authored-by: Ezio Melotti * Fix backticks --------- (cherry picked from commit 804c213c89366dd5ffa7feeb1bd4feccfee75b38) Co-authored-by: Micah Najacht Co-authored-by: Ezio Melotti Co-authored-by: Serhiy Storchaka --- Doc/library/html.parser.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Doc/library/html.parser.rst b/Doc/library/html.parser.rst index 3f075bb8cbae5c..a673fd3df911cc 100644 --- a/Doc/library/html.parser.rst +++ b/Doc/library/html.parser.rst @@ -141,7 +141,7 @@ implementations do nothing (except for :meth:`~HTMLParser.handle_startendtag`): argument is a list of ``(name, value)`` pairs containing the attributes found inside the tag's ``<>`` brackets. The *name* will be translated to lower case, and quotes in the *value* have been removed, and character and entity references - have been replaced. + have been replaced. For empty attributes, *value* is ``None``. For instance, for the tag ````, this method would be called as ``handle_starttag('a', [('href', 'https://www.cwi.nl/')])``. @@ -317,6 +317,18 @@ without further parsing: Data : alert("hello! ☺"); End tag : script +Attribute names are converted to lowercase, quotes from attribute values removed, +and ``None`` is returned as *value* for empty attributes (such as ``checked``): + +.. doctest:: + + >>> parser.feed("") + Start tag: input + attr: ('type', 'checkbox') + attr: ('checked', None) + attr: ('required', '') + attr: ('disabled', 'disabled') + Parsing comments: .. doctest::