From 63a58407d46ca5c02c6cee12e7678e53770a4514 Mon Sep 17 00:00:00 2001 From: Fearless-Badger Date: Mon, 19 May 2025 23:33:38 -0400 Subject: [PATCH 1/3] Specify boolean attribute behavior in parser --- Doc/library/html.parser.rst | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Doc/library/html.parser.rst b/Doc/library/html.parser.rst index dd67fc34e856f1..c814c1627a13f0 100644 --- a/Doc/library/html.parser.rst +++ b/Doc/library/html.parser.rst @@ -134,7 +134,8 @@ 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. If a boolean attribute is encountered, the *value* for the + ``(name, value)`` attribute pair will be ``None``. For instance, for the tag ````, this method would be called as ``handle_starttag('a', [('href', 'https://www.cwi.nl/')])``. @@ -310,6 +311,16 @@ further parsing: Data : alert("hello!"); End tag : script +Boolean attributes have a *value* of ``None``: + +.. doctest:: + + >>> parser.feed("") + Start tag: script + attr: ('src', '/script.js') + attr: ('defer', None) + End tag : script + Parsing comments: .. doctest:: From 329327bcd185d46e780ee1cafde47d51ffb3fe34 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Sun, 26 Apr 2026 16:07:38 +0200 Subject: [PATCH 2/3] Tweak wording and example Co-authored-by: Serhiy Storchaka Co-authored-by: Ezio Melotti --- Doc/library/html.parser.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Doc/library/html.parser.rst b/Doc/library/html.parser.rst index c814c1627a13f0..008967c3c9d3e7 100644 --- a/Doc/library/html.parser.rst +++ b/Doc/library/html.parser.rst @@ -134,8 +134,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. If a boolean attribute is encountered, the *value* for the - ``(name, value)`` attribute pair will be ``None``. + 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/')])``. @@ -311,15 +310,17 @@ further parsing: Data : alert("hello!"); End tag : script -Boolean attributes have a *value* of ``None``: +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: script - attr: ('src', '/script.js') - attr: ('defer', None) - End tag : script + >>> parser.feed("") + Start tag: input + attr: ('type', 'checkbox') + attr: ('checked', None) + attr: ('required', '') + attr: ('disabled', 'disabled') Parsing comments: From 5b2b5de30e011fd59fc60f0b603eb38f374d41f5 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Sun, 26 Apr 2026 16:09:15 +0200 Subject: [PATCH 3/3] Fix backticks --- Doc/library/html.parser.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/html.parser.rst b/Doc/library/html.parser.rst index 008967c3c9d3e7..d7f97ad99ac5a7 100644 --- a/Doc/library/html.parser.rst +++ b/Doc/library/html.parser.rst @@ -311,7 +311,7 @@ further parsing: 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`): +and ``None`` is returned as *value* for empty attributes (such as ``checked``): .. doctest::