From fddcfa27fab71ceb6a9df3f4edf46e94ee1da94f Mon Sep 17 00:00:00 2001 From: Michael Foord Date: Mon, 14 Apr 2014 16:25:20 -0400 Subject: Closes issue 17660. You no longer need to explicitly pass create=True when patching builtin names. --- Lib/unittest/mock.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Lib/unittest/mock.py') diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index f1f65221d40..2dd4ca5271a 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -27,9 +27,13 @@ __version__ = '1.0' import inspect import pprint import sys +import builtins +from types import ModuleType from functools import wraps, partial +_builtins = {name for name in dir(builtins) if not name.startswith('_')} + BaseExceptions = (BaseException,) if 'java' in sys.platform: # jython @@ -1166,6 +1170,9 @@ class _patch(object): else: local = True + if name in _builtins and isinstance(target, ModuleType): + self.create = True + if not self.create and original is DEFAULT: raise AttributeError( "%s does not have the attribute %r" % (target, name) -- cgit v1.2.3