mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Closes issue 17660. You no longer need to explicitly pass create=True when patching builtin names.
This commit is contained in:
parent
fba913f77a
commit
fddcfa27fa
3 changed files with 52 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue