]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-82665 Mention that HTMLParser.handle_starttag value can be None (#134312)
authorMicah Najacht <micah.najacht@gmail.com>
Mon, 27 Apr 2026 06:27:05 +0000 (01:27 -0500)
committerGitHub <noreply@github.com>
Mon, 27 Apr 2026 06:27:05 +0000 (08:27 +0200)
* Specify boolean attribute behavior in parser

* Tweak wording and example

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
* Fix backticks

---------

Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Doc/library/html.parser.rst

index 341a8337ba2ceb87876fb5f50327160ae7369fa4..11f851d4f6c4b741e9ccc448d84f63f0b16c52a4 100644 (file)
@@ -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 ``<A HREF="https://www.cwi.nl/">``, this method
    would be called as ``handle_starttag('a', [('href', 'https://www.cwi.nl/')])``.
@@ -317,6 +317,18 @@ without further parsing:
    Data     : alert("<strong>hello! &#9786;</strong>");
    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("<input TYPE='checkbox' checked required='' disabled=disabled>")
+   Start tag: input
+        attr: ('type', 'checkbox')
+        attr: ('checked', None)
+        attr: ('required', '')
+        attr: ('disabled', 'disabled')
+
 Parsing comments:
 
 .. doctest::