This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients docs@python, ezio.melotti, martin.panter, r.david.murray, serhiy.storchaka, xkjq
Date 2015-03-08.11:32:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> 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.
Date User Action Args
2015-03-08 11:32:12ezio.melottisetrecipients: + ezio.melotti, r.david.murray, docs@python, martin.panter, serhiy.storchaka, xkjq
2015-03-08 11:32:12ezio.melottisetmessageid: <>
2015-03-08 11:32:12ezio.melottilinkissue23144 messages
2015-03-08 11:32:12ezio.melotticreate