[docs] [issue23144] html.parser.HTMLParser: setting 'convert_charrefs = True' leads to dropped text

Ezio Melotti report at bugs.python.org
Sun Mar 8 12:32:12 CET 2015

Ezio Melotti added the comment:

> A context manager here would seem a bit strange.

I still haven't thought this through, but I can't see any problem with it right now.  This would be similar to:

  from contextlib import closing
  with closing(MyHTMLParser()) as parser:

and this already seems to work fine, including with OP's case.

> If an exception is raised inside the context manager,
> should close() be called (like for file objects), or not?

The parser is guaranteed to never raise parsing-related errors during parsing, so this shouldn't be an issue.  I will open a new issue after fixing this so we can keep discussing there.


Python tracker <report at bugs.python.org>

More information about the docs mailing list