[issue15806] Add context manager for the try: ... except: pass pattern

2013-10-16 Thread Alexander Belopolsky
Changes by Alexander Belopolsky alexander.belopol...@gmail.com: -- superseder: - Rename contextlib.ignore to contextlib.suppress ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806 ___

[issue15806] Add context manager for the try: ... except: pass pattern

2013-10-11 Thread Giampaolo Rodola'
Changes by Giampaolo Rodola' g.rod...@gmail.com: -- nosy: +giampaolo.rodola ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806 ___ ___

[issue15806] Add context manager for the try: ... except: pass pattern

2013-08-22 Thread Yury V. Zaytsev
Yury V. Zaytsev added the comment: Hi Raymond, This is a brilliant idea, but before it hits the streets, couldn't you possibly consider extending it with a kwarg to control the depth of the exception stack? The use case I have for that are snippets like this: with ignored(ValueError,

[issue15806] Add context manager for the try: ... except: pass pattern

2013-08-22 Thread Yury V. Zaytsev
Yury V. Zaytsev added the comment: Actually, please disregard my idea. It's way to dangerous, especially in the case of multiple exceptions to ignore :-( -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806

[issue15806] Add context manager for the try: ... except: pass pattern

2013-03-15 Thread Barry A. Warsaw
Changes by Barry A. Warsaw ba...@python.org: -- nosy: +barry ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806 ___ ___ Python-bugs-list mailing

[issue15806] Add context manager for the try: ... except: pass pattern

2013-03-11 Thread Nick Coghlan
Nick Coghlan added the comment: FTR, Raymond and I discussed this on IRC and I gave it a +1 before he committed it. The advantage the callable form has over a class method is that it readily scales to ignoring multiple exception types in a single with statement. --

[issue15806] Add context manager for the try: ... except: pass pattern

2013-03-10 Thread Roundup Robot
Roundup Robot added the comment: New changeset 406b47c64480 by Raymond Hettinger in branch 'default': Issue #15806: Add contextlib.ignored(). http://hg.python.org/cpython/rev/406b47c64480 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org

[issue15806] Add context manager for the try: ... except: pass pattern

2013-03-10 Thread Raymond Hettinger
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806 ___

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Raymond Hettinger
Raymond Hettinger added the comment: Yes, something along those lines would be *much* better: class Ignore: ''' Context manager to ignore particular exceptions''' def __init__(self, *ignored_exceptions): self.ignored_exceptions = ignored_exceptions def __enter__(self):

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Nick Coghlan
Nick Coghlan added the comment: I'd just write it with @contextmanager. Making it easier to cleanly factor out exception handling is one of the main reasons that exists. @contextmanager def ignored(*exceptions): Context manager to ignore particular exceptions try: yield

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Chris Jerdonek
Changes by Chris Jerdonek chris.jerdo...@gmail.com: -- nosy: +cjerdonek ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806 ___ ___

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Ezio Melotti
Ezio Melotti added the comment: I think I'm -1 on this. This saves two lines, but makes the code less explicit, it can't be used for try/except/else or try/except/except, it requires an extra import, the implementation is simple enough that it doesn't necessary need to be in the stdlib, it

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Martin v . Löwis
Martin v. Löwis added the comment: I think the zipfile example is really a bad example. IMO, it would best be written as try: return bool(EndRecData(fp)) except IOError: return False i.e. there shouldn't be a pass statement at all in this code, and the if can be dropped whether you use

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Chris Rebert
Changes by Chris Rebert pyb...@rebertia.com: -- nosy: +cvrebert ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806 ___ ___ Python-bugs-list

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Nick Coghlan
Nick Coghlan added the comment: (Note: I'm not yet convinced this is a good idea. I'm definitely considering it, though) As with many context managers, a key benefit here is in the priming effect for readers. In this code: try: # Whatever except (A, B, C): pass the

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Ezio Melotti
Ezio Melotti added the comment: As with many context managers, a key benefit here is in the priming effect for readers. The focus is mostly on what it's being executed rather than what it's being ignored though. Do this operation and ignore these exceptions if they occur vs. Ignore these

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Antoine Pitrou
Antoine Pitrou added the comment: If this is desirable then I think it would be better as a classmethod of Exception: with KeyError.trap(): do_something() -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Eric V. Smith
Eric V. Smith added the comment: While the classmethod version has some appeal, it doesn't extend well to handling multiple exception types. I'm -0 on this, in any event. I think the original code is more clear. Why force people to learn (or recognize) a second idiom for something so simple?

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-29 Thread Jesús Cea Avión
Changes by Jesús Cea Avión j...@jcea.es: -- nosy: +jcea ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806 ___ ___ Python-bugs-list mailing list

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-28 Thread Raymond Hettinger
New submission from Raymond Hettinger: It is a somewhat common pattern to write: try: do_something() except SomeException: pass To search examples in the standard library (or any other code base) use: $ egrep -C2 except( [A-Za-z]+)?: *py | grep -C2 pass In the

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-28 Thread Alex Gaynor
Changes by Alex Gaynor alex.gay...@gmail.com: -- nosy: +alex ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806 ___ ___ Python-bugs-list mailing

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: Hmm, the __exit__ method was doing exact matches by exception type, so KeyError wouldn't match LookupError or Exception. There are probably a number of ways to fix this, but it may be easiest to use the builtin exception catching mechanisms: class Ignore:

[issue15806] Add context manager for the try: ... except: pass pattern

2012-08-28 Thread Alex Gaynor
Alex Gaynor added the comment: Why not just: issubclass(exctype, self.exception_types)? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15806 ___