Skip to content

Commit 804c213

Browse files
Fearless-Badgerezio-melottiserhiy-storchaka
authored
gh-82665 Mention that HTMLParser.handle_starttag value can be None (#134312)
* 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>
1 parent f27e91e commit 804c213

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Doc/library/html.parser.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ implementations do nothing (except for :meth:`~HTMLParser.handle_startendtag`):
141141
argument is a list of ``(name, value)`` pairs containing the attributes found
142142
inside the tag's ``<>`` brackets. The *name* will be translated to lower case,
143143
and quotes in the *value* have been removed, and character and entity references
144-
have been replaced.
144+
have been replaced. For empty attributes, *value* is ``None``.
145145

146146
For instance, for the tag ``<A HREF="https://www.cwi.nl/">``, this method
147147
would be called as ``handle_starttag('a', [('href', 'https://www.cwi.nl/')])``.
@@ -317,6 +317,18 @@ without further parsing:
317317
Data : alert("<strong>hello! &#9786;</strong>");
318318
End tag : script
319319

320+
Attribute names are converted to lowercase, quotes from attribute values removed,
321+
and ``None`` is returned as *value* for empty attributes (such as ``checked``):
322+
323+
.. doctest::
324+
325+
>>> parser.feed("<input TYPE='checkbox' checked required='' disabled=disabled>")
326+
Start tag: input
327+
attr: ('type', 'checkbox')
328+
attr: ('checked', None)
329+
attr: ('required', '')
330+
attr: ('disabled', 'disabled')
331+
320332
Parsing comments:
321333

322334
.. doctest::

0 commit comments

Comments
 (0)