mirror of
https://github.com/ansible/awx.git
synced 2026-07-10 07:48:05 -02:30
Use built-in suppress from contextlib
In python3, we can use the built-in suppress from contextlib https://docs.python.org/3/library/contextlib.html#contextlib.suppress
This commit is contained in:
@@ -362,28 +362,6 @@ def are_same_endpoint(first, second):
|
||||
return strip(first) == strip(second)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def suppress(*exceptions):
|
||||
"""Context manager that suppresses the provided exceptions
|
||||
|
||||
:param exceptions: List of exceptions to suppress
|
||||
|
||||
Usage::
|
||||
>>> with suppress(ZeroDivisionError):
|
||||
>>> foo = 1/0
|
||||
>>> # This code will not run
|
||||
|
||||
Note: This is an intermediate framework and test refactoring tool.
|
||||
It's almost never a good idea to plan on using this. Also, note
|
||||
that after the suppressed exception has been caught, no further
|
||||
statements in the with block will be executed.
|
||||
"""
|
||||
try:
|
||||
yield
|
||||
except exceptions:
|
||||
pass
|
||||
|
||||
|
||||
def utcnow():
|
||||
"""Provide a wrapped copy of the built-in utcnow that can be easily mocked."""
|
||||
return datetime.utcnow()
|
||||
|
||||
Reference in New Issue
Block a user