[issue32158] Suppress (and other contextlib context managers) should work as decorators (where appropriate)

2018-02-09 Thread R. David Murray
R. David Murray added the comment: The designed use case of suppress is to cover a *single line* of python code. It should *not* be a decorator. -- nosy: +r.david.murray ___ Python tracker _

[issue32158] Suppress (and other contextlib context managers) should work as decorators (where appropriate)

2018-02-09 Thread Jason R. Coombs
Jason R. Coombs added the comment: In [this question](https://stackoverflow.com/a/48710609/70170), I encounter another case where a decorator would be useful. Without the decorator: def is_docker(): path = '/proc/self/cgroup' return ( os.path.exists('/.dockerenv

[issue32158] Suppress (and other contextlib context managers) should work as decorators (where appropriate)

2017-11-28 Thread Barry A. Warsaw
Change by Barry A. Warsaw : -- nosy: +barry ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pytho

[issue32158] Suppress (and other contextlib context managers) should work as decorators (where appropriate)

2017-11-28 Thread Jason R. Coombs
Jason R. Coombs added the comment: Fair enough. For an example, here's the case where I wanted to use the decorator to avoid excess indentation and keep the most meaningful part of the function at the base of the body: @suppress(KeyError) def v12_to_13(manager, case): case['sample_id'] =

[issue32158] Suppress (and other contextlib context managers) should work as decorators (where appropriate)

2017-11-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: > But it got me thinking - couldn't suppress (and possibly other) > contextlib decorators support this usage out of the box? They possibly could but probably shouldn't. My experience is that giving them a dual role makes them more complicated and harder t

[issue32158] Suppress (and other contextlib context managers) should work as decorators (where appropriate)

2017-11-28 Thread Jason R. Coombs
New submission from Jason R. Coombs : The contextlib docs explain why a decorator is nice: > It makes it clear that the cm applies to the whole function, rather than just > a piece of it (and saving an indentation level is nice, too). However, the built-in context managers that could readily s