[Python-checkins] cpython: Removed XXX from unittest.mock docstring and switch to a nicer
michael.foord
python-checkins at python.org
Wed Mar 14 22:57:02 CET 2012
http://hg.python.org/cpython/rev/d695be318949
changeset: 75649:d695be318949
user: Michael Foord <michael at voidspace.org.uk>
date: Wed Mar 14 14:56:54 2012 -0700
summary:
Removed XXX from unittest.mock docstring and switch to a nicer try...except...finally
files:
Lib/unittest/mock.py | 41 ++++++++++++++-----------------
1 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -619,9 +619,7 @@
def __dir__(self):
- """Filter the output of `dir(mock)` to only useful members.
- XXXX
- """
+ """Filter the output of `dir(mock)` to only useful members."""
extras = self._mock_methods or []
from_type = dir(type(self))
from_dict = list(self.__dict__)
@@ -1057,31 +1055,28 @@
@wraps(func)
def patched(*args, **keywargs):
- # could use with statement here
extra_args = []
entered_patchers = []
- # could use try..except...finally here
try:
- try:
- for patching in patched.patchings:
- arg = patching.__enter__()
- entered_patchers.append(patching)
- if patching.attribute_name is not None:
- keywargs.update(arg)
- elif patching.new is DEFAULT:
- extra_args.append(arg)
+ for patching in patched.patchings:
+ arg = patching.__enter__()
+ entered_patchers.append(patching)
+ if patching.attribute_name is not None:
+ keywargs.update(arg)
+ elif patching.new is DEFAULT:
+ extra_args.append(arg)
- args += tuple(extra_args)
- return func(*args, **keywargs)
- except:
- if (patching not in entered_patchers and
- _is_started(patching)):
- # the patcher may have been started, but an exception
- # raised whilst entering one of its additional_patchers
- entered_patchers.append(patching)
- # re-raise the exception
- raise
+ args += tuple(extra_args)
+ return func(*args, **keywargs)
+ except:
+ if (patching not in entered_patchers and
+ _is_started(patching)):
+ # the patcher may have been started, but an exception
+ # raised whilst entering one of its additional_patchers
+ entered_patchers.append(patching)
+ # re-raise the exception
+ raise
finally:
for patching in reversed(entered_patchers):
patching.__exit__()
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list