[Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore()) (original) (raw)
Gregory P. Smith greg at krypto.org
Fri Oct 18 02:23:50 CEST 2013
- Previous message: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())
- Next message: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Right again. The simplest rule to remember seems to be "don't use yield or yield-from inside a with-statement". You can relax it by limiting it to context managers that manage any kind of shared resource, but that is probably already too subtle: e.g. yielding inside "with open(file) as f" seems fine, but yielding inside "with lock" is problematic, since the other side might try to acquire the same lock, and deadlock.
This seems like the kind of thing that might warrant a pylint warning. Probably the more general case, requiring people to think about it and suppress the warning with an explanatory comment (or write the code in a different manner) when they are doing something known to be safe.
-gps -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20131017/0ec4c985/attachment-0001.html>
- Previous message: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())
- Next message: [Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]