[Python-projects] astng: generator ignored GeneratorExit
Sylvain Thénault
sylvain.thenault at logilab.fr
Tue May 13 12:15:27 CEST 2008
On Mon, May 12, 2008 at 12:23:31PM +0200, Maarten ter Huurne wrote:
> Hi,
Hey Maarteen,
> When I run pylint on the following program:
> ===
> print {}[str(0) + ''].a
> ===
>
> I see this message:
> ===
> Exception exceptions.RuntimeError: 'generator ignored GeneratorExit' in
> <generator object at 0x835096c> ignored
> ===
>
> Versions used:
> ===
> pylint 0.14.0,
> astng 0.17.2, common 0.31.0
> Python 2.5.1 (r251:54863, Jan 10 2008, 18:01:57)
> ===
>
> Python 2.5 is essential to trigger this issue, since GeneratorExit was
> introduced in that release.
>
> The problem seems to be that _infer_operator() uses an "except:" clause that
> catches all exceptions and then yields YES. Since GeneratorExit is an
> exception, this means the generator will yield another value after the
> Python VM told it to stop, which is the reason the Python VM prints that
> message.
>
> There is a patch at the end of this mail.
great, thank you very much for tracking this.
> In general, it seems to be unsafe to have a "yield" in a "try" body and in a
> following "except:" or "except Exception:" clause, unless GeneratorExit is
> explicitly dealt with in an earlier "except" clause. Maybe this could
> become a new pylint rule?
http://www.logilab.org/ticket/4983
cheers,
--
Sylvain Thénault LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
Python et calcul scientifique: http://www.logilab.fr/science
More information about the Python-Projects
mailing list