diff options
author | Georg Brandl <georg@python.org> | 2007-12-02 09:40:06 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-12-02 09:40:06 +0000 |
commit | 1a3284ed69d545e4ef59869998cb8c29233a45fa (patch) | |
tree | 98728a9b7aae6188ee8124160007a9d5c5277f8c /Lib | |
parent | 87f9c53937ce47f55851ac7c71a94e46cf9142bf (diff) | |
download | cpython-git-1a3284ed69d545e4ef59869998cb8c29233a45fa.tar.gz |
#1535: rename __builtin__ module to builtins.
Diffstat (limited to 'Lib')
34 files changed, 154 insertions, 155 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py index 085fa90863..9b41c35128 100644 --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -135,7 +135,7 @@ writeframesraw. """ import struct -import __builtin__ +import builtins __all__ = ["Error","open","openfp"] @@ -336,7 +336,7 @@ class Aifc_read: def __init__(self, f): if type(f) == type(''): - f = __builtin__.open(f, 'rb') + f = builtins.open(f, 'rb') # else, assume it is an open file object already self.initfp(f) @@ -557,7 +557,7 @@ class Aifc_write: def __init__(self, f): if type(f) == type(''): filename = f - f = __builtin__.open(f, 'wb') + f = builtins.open(f, 'wb') else: # else, assume it is an open file object already filename = '???' diff --git a/Lib/codecs.py b/Lib/codecs.py index 982c282592..06cec17a7c 100644 --- a/Lib/codecs.py +++ b/Lib/codecs.py @@ -7,7 +7,7 @@ Written by Marc-Andre Lemburg (mal@lemburg.com). """#" -import __builtin__, sys +import builtins, sys ### Registry and builtin stateless codec functions @@ -858,7 +858,7 @@ def open(filename, mode='rb', encoding=None, errors='strict', buffering=1): 'b' not in mode: # Force opening of the file in binary mode mode = mode + 'b' - file = __builtin__.open(filename, mode, buffering) + file = builtins.open(filename, mode, buffering) if encoding is None: return file info = lookup(encoding) diff --git a/Lib/dumbdbm.py b/Lib/dumbdbm.py index 7741fbb83e..e44e1f5fd5 100644 --- a/Lib/dumbdbm.py +++ b/Lib/dumbdbm.py @@ -23,7 +23,6 @@ is read when the database is opened, and some updates rewrite the whole index) import io as _io import os as _os -import __builtin__ import UserDict _BLOCKSIZE = 512 diff --git a/Lib/gettext.py b/Lib/gettext.py index be24f1dc62..6e14a9354a 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -236,18 +236,18 @@ class NullTranslations: self._output_charset = charset def install(self, str=False, names=None): - import __builtin__ - __builtin__.__dict__['_'] = str and self.ugettext or self.gettext + import builtins + builtins.__dict__['_'] = str and self.ugettext or self.gettext if hasattr(names, "__contains__"): if "gettext" in names: - __builtin__.__dict__['gettext'] = __builtin__.__dict__['_'] + builtins.__dict__['gettext'] = builtins.__dict__['_'] if "ngettext" in names: - __builtin__.__dict__['ngettext'] = (str and self.ungettext + builtins.__dict__['ngettext'] = (str and self.ungettext or self.ngettext) if "lgettext" in names: - __builtin__.__dict__['lgettext'] = self.lgettext + builtins.__dict__['lgettext'] = self.lgettext if "lngettext" in names: - __builtin__.__dict__['lngettext'] = self.lngettext + builtins.__dict__['lngettext'] = self.lngettext class GNUTranslations(NullTranslations): diff --git a/Lib/gzip.py b/Lib/gzip.py index 4f750c068d..a04408784e 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -7,7 +7,7 @@ but random access is not allowed.""" import struct, sys, time import zlib -import __builtin__ +import builtins __all__ = ["GzipFile","open"] @@ -92,7 +92,7 @@ class GzipFile: if mode and 'b' not in mode: mode += 'b' if fileobj is None: - fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb') + fileobj = self.myfileobj = builtins.open(filename, mode or 'rb') if filename is None: if hasattr(fileobj, 'name'): filename = fileobj.name else: filename = '' @@ -487,13 +487,13 @@ def _test(): print("filename doesn't end in .gz:", repr(arg)) continue f = open(arg, "rb") - g = __builtin__.open(arg[:-3], "wb") + g = builtins.open(arg[:-3], "wb") else: if arg == "-": f = sys.stdin g = GzipFile(filename="", mode="wb", fileobj=sys.stdout) else: - f = __builtin__.open(arg, "rb") + f = builtins.open(arg, "rb") g = open(arg + ".gz", "wb") while True: chunk = f.read(1024) diff --git a/Lib/idlelib/ColorDelegator.py b/Lib/idlelib/ColorDelegator.py index b93aa5abb1..e7112c93a0 100644 --- a/Lib/idlelib/ColorDelegator.py +++ b/Lib/idlelib/ColorDelegator.py @@ -1,7 +1,7 @@ import time import re import keyword -import __builtin__ +import builtins from Tkinter import * from idlelib.Delegator import Delegator from idlelib.configHandler import idleConf @@ -14,7 +14,7 @@ def any(name, alternates): def make_pat(): kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b" - builtinlist = [str(name) for name in dir(__builtin__) + builtinlist = [str(name) for name in dir(builtins) if not name.startswith('_')] # self.file = open("file") : # 1st 'file' colorized normal, 2nd as builtin, 3rd as string diff --git a/Lib/idlelib/RemoteDebugger.py b/Lib/idlelib/RemoteDebugger.py index e5b95b4e6b..46582d10ea 100644 --- a/Lib/idlelib/RemoteDebugger.py +++ b/Lib/idlelib/RemoteDebugger.py @@ -172,7 +172,7 @@ class IdbAdapter: def dict_item(self, did, key): dict = dicttable[did] value = dict[key] - value = repr(value) ### can't pickle module '__builtin__' + value = repr(value) ### can't pickle module 'builtins' return value #----------end class IdbAdapter---------- diff --git a/Lib/ihooks.py b/Lib/ihooks.py index d2eabc4cdd..433f51341a 100644 --- a/Lib/ihooks.py +++ b/Lib/ihooks.py @@ -49,7 +49,7 @@ by the way the __import__ hook is used by the Python interpreter.) """ -import __builtin__ +import builtins import imp import os import sys @@ -375,18 +375,18 @@ class BasicModuleImporter(_Verbose): # XXX Should this try to clear the module's namespace? def install(self): - self.save_import_module = __builtin__.__import__ - if not hasattr(__builtin__, 'unload'): - __builtin__.unload = None - self.save_unload = __builtin__.unload - __builtin__.__import__ = self.import_module - __builtin__.unload = self.unload + self.save_import_module = builtins.__import__ + if not hasattr(builtins, 'unload'): + builtins.unload = None + self.save_unload = builtins.unload + builtins.__import__ = self.import_module + builtins.unload = self.unload def uninstall(self): - __builtin__.__import__ = self.save_import_module - __builtin__.unload = self.save_unload - if not __builtin__.unload: - del __builtin__.unload + builtins.__import__ = self.save_import_module + builtins.unload = self.save_unload + if not builtins.unload: + del builtins.unload class ModuleImporter(BasicModuleImporter): diff --git a/Lib/imputil.py b/Lib/imputil.py index 1d09ba5308..4278e31d78 100644 --- a/Lib/imputil.py +++ b/Lib/imputil.py @@ -13,7 +13,7 @@ Exported classes: # note: avoid importing non-builtin modules import imp ### not available in JPython? import sys -import __builtin__ +import builtins # for the DirectoryImporter import struct @@ -26,7 +26,7 @@ _ModuleType = type(sys) ### doesn't work in JPython... class ImportManager: "Manage the import process." - def install(self, namespace=vars(__builtin__)): + def install(self, namespace=vars(builtins)): "Install this ImportManager into the specified namespace." if isinstance(namespace, _ModuleType): @@ -404,7 +404,7 @@ def _compile(pathname, timestamp): codestring = open(pathname, 'rU').read() if codestring and codestring[-1] != '\n': codestring = codestring + '\n' - code = __builtin__.compile(codestring, pathname, 'exec') + code = builtins.compile(codestring, pathname, 'exec') # try to cache the compiled code try: diff --git a/Lib/inspect.py b/Lib/inspect.py index a1910e4ff9..994dbdc51b 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -444,7 +444,7 @@ def getmodule(object, _filename=None): if mainobject is object: return main # Check builtins - builtin = sys.modules['__builtin__'] + builtin = sys.modules['builtins'] if hasattr(builtin, object.__name__): builtinobject = getattr(builtin, object.__name__) if builtinobject is object: @@ -775,7 +775,7 @@ def strseq(object, convert, join=joinseq): def formatannotation(annotation, base_module=None): if isinstance(annotation, type): - if annotation.__module__ in ('__builtin__', base_module): + if annotation.__module__ in ('builtins', base_module): return annotation.__name__ return annotation.__module__+'.'+annotation.__name__ return repr(annotation) @@ -184,7 +184,7 @@ def open(file, mode="r", buffering=None, encoding=None, newline=None, class OpenWrapper: - """Wrapper for __builtin__.open + """Wrapper for builtins.open Trick so that open won't become a bound method when stored as a class variable (as dumbdbm does). diff --git a/Lib/locale.py b/Lib/locale.py index 3f30ca07ac..ce0ca817eb 100644 --- a/Lib/locale.py +++ b/Lib/locale.py @@ -12,7 +12,7 @@ """ import sys, encodings, encodings.aliases -from __builtin__ import str as _builtin_str +from builtins import str as _builtin_str # Try importing the _locale module. # diff --git a/Lib/optparse.py b/Lib/optparse.py index f702e1a845..ab2ce40077 100644 --- a/Lib/optparse.py +++ b/Lib/optparse.py @@ -636,13 +636,13 @@ class Option: else: # Allow type objects or builtin type conversion functions # (int, str, etc.) as an alternative to their names. (The - # complicated check of __builtin__ is only necessary for + # complicated check of builtins is only necessary for # Python 2.1 and earlier, and is short-circuited by the # first check on modern Pythons.) - import __builtin__ + import builtins if ( isinstance(self.type, type) or (hasattr(self.type, "__name__") and - getattr(__builtin__, self.type.__name__, None) is self.type) ): + getattr(builtins, self.type.__name__, None) is self.type) ): self.type = self.type.__name__ if self.type == "str": diff --git a/Lib/pickletools.py b/Lib/pickletools.py index af84c1f8b9..0665cd0bca 100644 --- a/Lib/pickletools.py +++ b/Lib/pickletools.py @@ -2054,25 +2054,25 @@ highest protocol among opcodes = 0 33: ( MARK 34: c GLOBAL 'pickletools _Example' 56: p PUT 2 - 59: c GLOBAL '__builtin__ object' - 79: p PUT 3 - 82: N NONE - 83: t TUPLE (MARK at 33) - 84: p PUT 4 - 87: R REDUCE - 88: p PUT 5 - 91: ( MARK - 92: d DICT (MARK at 91) - 93: p PUT 6 - 96: V UNICODE 'value' - 103: p PUT 7 - 106: L LONG 42 - 110: s SETITEM - 111: b BUILD - 112: a APPEND - 113: g GET 5 - 116: a APPEND - 117: . STOP + 59: c GLOBAL 'builtins object' + 76: p PUT 3 + 79: N NONE + 80: t TUPLE (MARK at 33) + 81: p PUT 4 + 84: R REDUCE + 85: p PUT 5 + 88: ( MARK + 89: d DICT (MARK at 88) + 90: p PUT 6 + 93: V UNICODE 'value' + 100: p PUT 7 + 103: L LONG 42 + 107: s SETITEM + 108: b BUILD + 109: a APPEND + 110: g GET 5 + 113: a APPEND + 114: . STOP highest protocol among opcodes = 0 >>> dis(pickle.dumps(x, 1)) @@ -2084,23 +2084,23 @@ highest protocol among opcodes = 0 31: ( MARK 32: c GLOBAL 'pickletools _Example' 54: q BINPUT 2 - 56: c GLOBAL '__builtin__ object' - 76: q BINPUT 3 - 78: N NONE - 79: t TUPLE (MARK at 31) - 80: q BINPUT 4 - 82: R REDUCE - 83: q BINPUT 5 - 85: } EMPTY_DICT - 86: q BINPUT 6 - 88: X BINUNICODE 'value' - 98: q BINPUT 7 - 100: K BININT1 42 - 102: s SETITEM - 103: b BUILD - 104: h BINGET 5 - 106: e APPENDS (MARK at 3) - 107: . STOP + 56: c GLOBAL 'builtins object' + 73: q BINPUT 3 + 75: N NONE + 76: t TUPLE (MARK at 31) + 77: q BINPUT 4 + 79: R REDUCE + 80: q BINPUT 5 + 82: } EMPTY_DICT + 83: q BINPUT 6 + 85: X BINUNICODE 'value' + 95: q BINPUT 7 + 97: K BININT1 42 + 99: s SETITEM + 100: b BUILD + 101: h BINGET 5 + 103: e APPENDS (MARK at 3) + 104: . STOP highest protocol among opcodes = 1 Try "the canonical" recursive-object test. diff --git a/Lib/plat-mac/icopen.py b/Lib/plat-mac/icopen.py index eea6083797..146a333972 100644 --- a/Lib/plat-mac/icopen.py +++ b/Lib/plat-mac/icopen.py @@ -37,9 +37,9 @@ The next time you launch PythonInterpreter or Python IDE, the patch will take effect. """ -import __builtin__ +import builtins -_builtin_open = globals().get('_builtin_open', __builtin__.open) +_builtin_open = globals().get('_builtin_open', builtins.open) def _open_with_typer(*args): file = _builtin_open(*args) @@ -55,7 +55,7 @@ def _open_with_typer(*args): pass return file -__builtin__.open = _open_with_typer +builtins.open = _open_with_typer """ open('test.py') diff --git a/Lib/py_compile.py b/Lib/py_compile.py index 912972bcac..982d19d142 100644 --- a/Lib/py_compile.py +++ b/Lib/py_compile.py @@ -3,7 +3,7 @@ This module has intimate knowledge of the format of .pyc files. """ -import __builtin__ +import builtins import imp import marshal import os @@ -139,7 +139,7 @@ def compile(file, cfile=None, dfile=None, doraise=False): if codestring and codestring[-1] != '\n': codestring = codestring + '\n' try: - codeobject = __builtin__.compile(codestring, dfile or file,'exec') + codeobject = builtins.compile(codestring, dfile or file,'exec') except Exception as err: py_exc = PyCompileError(err.__class__, err, dfile or file) if doraise: diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 51d627ea4d..d94c3d30da 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -52,7 +52,7 @@ Richard Chamberlain, for the first implementation of textdoc. # the current directory is changed with os.chdir(), an incorrect # path will be displayed. -import sys, imp, os, re, inspect, __builtin__, pkgutil +import sys, imp, os, re, inspect, builtins, pkgutil from repr import Repr try: from collections import deque @@ -787,7 +787,7 @@ class HTMLDoc(Doc): thisclass = attrs[0][2] attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass) - if thisclass is __builtin__.object: + if thisclass is builtins.object: attrs = inherited continue elif thisclass is object: @@ -1184,7 +1184,7 @@ class TextDoc(Doc): thisclass = attrs[0][2] attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass) - if thisclass is __builtin__.object: + if thisclass is builtins.object: attrs = inherited continue elif thisclass is object: @@ -1450,8 +1450,8 @@ def locate(path, forceload=0): except AttributeError: return None return object else: - if hasattr(__builtin__, path): - return getattr(__builtin__, path) + if hasattr(builtins, path): + return getattr(builtins, path) # --------------------------------------- interactive interpreter interface diff --git a/Lib/repr.py b/Lib/repr.py index ceb36f9d73..9893c71cb8 100644 --- a/Lib/repr.py +++ b/Lib/repr.py @@ -2,7 +2,7 @@ __all__ = ["Repr","repr"] -import __builtin__ +import builtins from itertools import islice class Repr: @@ -84,16 +84,16 @@ class Repr: return '{%s}' % (s,) def repr_str(self, x, level): - s = __builtin__.repr(x[:self.maxstring]) + s = builtins.repr(x[:self.maxstring]) if len(s) > self.maxstring: i = max(0, (self.maxstring-3)//2) j = max(0, self.maxstring-3-i) - s = __builtin__.repr(x[:i] + x[len(x)-j:]) + s = builtins.repr(x[:i] + x[len(x)-j:]) s = s[:i] + '...' + s[len(s)-j:] return s def repr_int(self, x, level): - s = __builtin__.repr(x) # XXX Hope this isn't too slow... + s = builtins.repr(x) # XXX Hope this isn't too slow... if len(s) > self.maxlong: i = max(0, (self.maxlong-3)//2) j = max(0, self.maxlong-3-i) @@ -102,7 +102,7 @@ class Repr: def repr_instance(self, x, level): try: - s = __builtin__.repr(x) + s = builtins.repr(x) # Bugs in x.__repr__() can cause arbitrary # exceptions -- then make up something except Exception: diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py index 1c5750baa0..74b2e47a81 100644 --- a/Lib/rlcompleter.py +++ b/Lib/rlcompleter.py @@ -33,7 +33,7 @@ used, and this module (and the readline module) are silently inactive. """ -import __builtin__ +import builtins import __main__ __all__ = ["Completer"] @@ -97,7 +97,7 @@ class Completer: matches = [] n = len(text) for list in [keyword.kwlist, - __builtin__.__dict__, + builtins.__dict__, self.namespace]: for word in list: if word[:n] == text and word != "__builtins__": diff --git a/Lib/site.py b/Lib/site.py index f1db89c9f0..b97f945aa6 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -60,7 +60,7 @@ ImportError exception, it is silently ignored. import sys import os -import __builtin__ +import builtins def makepath(*paths): @@ -251,8 +251,8 @@ def setquit(): except: pass raise SystemExit(code) - __builtin__.quit = Quitter('quit') - __builtin__.exit = Quitter('exit') + builtins.quit = Quitter('quit') + builtins.exit = Quitter('exit') class _Printer(object): @@ -319,18 +319,18 @@ class _Printer(object): break def setcopyright(): - """Set 'copyright' and 'credits' in __builtin__""" - __builtin__.copyright = _Printer("copyright", sys.copyright) + """Set 'copyright' and 'credits' in builtins""" + builtins.copyright = _Printer("copyright", sys.copyright) if sys.platform[:4] == 'java': - __builtin__.credits = _Printer( + builtins.credits = _Printer( "credits", "Jython is maintained by the Jython developers (www.jython.org).") else: - __builtin__.credits = _Printer("credits", """\ + builtins.credits = _Printer("credits", """\ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands for supporting Python development. See www.python.org for more information.""") here = os.path.dirname(os.__file__) - __builtin__.license = _Printer( + builtins.license = _Printer( "license", "See http://www.python.org/%.3s/license.html" % sys.version, ["LICENSE.txt", "LICENSE"], [os.path.join(here, os.pardir), here, os.curdir]) @@ -350,7 +350,7 @@ class _Helper(object): return pydoc.help(*args, **kwds) def sethelper(): - __builtin__.help = _Helper() + builtins.help = _Helper() def aliasmbcs(): """On Windows, some default encodings are not provided by Python, diff --git a/Lib/sunau.py b/Lib/sunau.py index f2555025d9..b312501b35 100644 --- a/Lib/sunau.py +++ b/Lib/sunau.py @@ -153,8 +153,8 @@ class Au_read: def __init__(self, f): if type(f) == type(''): - import __builtin__ - f = __builtin__.open(f, 'rb') + import builtins + f = builtins.open(f, 'rb') self.initfp(f) def __del__(self): @@ -282,8 +282,8 @@ class Au_write: def __init__(self, f): if type(f) == type(''): - import __builtin__ - f = __builtin__.open(f, 'wb') + import builtins + f = builtins.open(f, 'wb') self.initfp(f) def __del__(self): diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 23252f4e61..f8afae9f5b 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -65,7 +65,7 @@ except ImportError: # from tarfile import * __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"] -from __builtin__ import open as _open # Since 'open' is TarFile.open +from builtins import open as _open # Since 'open' is TarFile.open #--------------------------------------------------------- # tar constants diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 6db3572d3a..b20f599294 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -91,7 +91,7 @@ class use_metaclass(object, metaclass=metaclass): DATA0 = ( b'(lp0\nL0\naL1\naF2.0\nac' - b'__builtin__\ncomplex\n' + b'builtins\ncomplex\n' b'p1\n(F3.0\nF0.0\ntp2\nRp' b'3\naL1\naL-1\naL255\naL-' b'255\naL-256\naL65535\na' @@ -100,8 +100,8 @@ DATA0 = ( b'647\naL-2147483648\na(' b'Vabc\np4\ng4\nccopy_reg' b'\n_reconstructor\np5\n(' - b'c__main__\nC\np6\nc__bu' - b'iltin__\nobject\np7\nNt' + b'c__main__\nC\np6\ncbu' + b'iltins\nobject\np7\nNt' b'p8\nRp9\n(dp10\nVfoo\np1' b'1\nL1\nsVbar\np12\nL2\nsb' b'g9\ntp13\nag13\naL5\na.' @@ -118,7 +118,7 @@ DATA0_DIS = """\ 12: a APPEND 13: F FLOAT 2.0 18: a APPEND - 19: c GLOBAL '__builtin__ complex' + 19: c GLOBAL 'builtins complex' 40: p PUT 1 43: ( MARK 44: F FLOAT 3.0 @@ -159,7 +159,7 @@ DATA0_DIS = """\ 199: ( MARK 200: c GLOBAL '__main__ C' 212: p PUT 6 - 215: c GLOBAL '__builtin__ object' + 215: c GLOBAL 'builtins object' 235: p PUT 7 238: N NONE 239: t TUPLE (MARK at 199) @@ -191,15 +191,15 @@ highest protocol among opcodes = 0 """ DATA1 = ( - b']q\x00(K\x00K\x01G@\x00\x00\x00\x00\x00\x00\x00c__' - b'builtin__\ncomplex\nq\x01' + b']q\x00(K\x00K\x01G@\x00\x00\x00\x00\x00\x00\x00c' + b'builtins\ncomplex\nq\x01' b'(G@\x08\x00\x00\x00\x00\x00\x00G\x00\x00\x00\x00\x00\x00\x00\x00t' b'q\x02Rq\x03K\x01J\xff\xff\xff\xffK\xffJ\x01\xff\xff\xffJ' b'\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff\xff' b'\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00\x80(X\x03\x00\x00\x00ab' b'cq\x04h\x04ccopy_reg\n_reco' b'nstructor\nq\x05(c__main' - b'__\nC\nq\x06c__builtin__\n' + b'__\nC\nq\x06cbuiltins\n' b'object\nq\x07Ntq\x08Rq\t}q\n(' b'X\x03\x00\x00\x00fooq\x0bK\x01X\x03\x00\x00\x00bar' b'q\x0cK\x02ubh\ttq\rh\rK\x05e.' @@ -213,7 +213,7 @@ DATA1_DIS = """\ 4: K BININT1 0 6: K BININT1 1 8: G BINFLOAT 2.0 - 17: c GLOBAL '__builtin__ complex' + 17: c GLOBAL 'builtins complex' 38: q BINPUT 1 40: ( MARK 41: G BINFLOAT 3.0 @@ -242,7 +242,7 @@ DATA1_DIS = """\ 152: ( MARK 153: c GLOBAL '__main__ C' 165: q BINPUT 6 - 167: c GLOBAL '__builtin__ object' + 167: c GLOBAL 'builtins object' 187: q BINPUT 7 189: N NONE 190: t TUPLE (MARK at 152) @@ -272,7 +272,7 @@ highest protocol among opcodes = 1 DATA2 = ( b'\x80\x02]q\x00(K\x00K\x01G@\x00\x00\x00\x00\x00\x00\x00c' - b'__builtin__\ncomplex\n' + b'builtins\ncomplex\n' b'q\x01G@\x08\x00\x00\x00\x00\x00\x00G\x00\x00\x00\x00\x00\x00\x00\x00' b'\x86q\x02Rq\x03K\x01J\xff\xff\xff\xffK\xffJ\x01\xff\xff\xff' b'J\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff' @@ -292,7 +292,7 @@ DATA2_DIS = """\ 6: K BININT1 0 8: K BININT1 1 10: G BINFLOAT 2.0 - 19: c GLOBAL '__builtin__ complex' + 19: c GLOBAL 'builtins complex' 40: q BINPUT 1 42: G BINFLOAT 3.0 51: G BINFLOAT 0.0 diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index e7ffc02b7d..cc490d722f 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -7,10 +7,10 @@ class TestSpecifics(unittest.TestCase): def test_debug_assignment(self): # catch assignments to __debug__ self.assertRaises(SyntaxError, compile, '__debug__ = 1', '?', 'single') - import __builtin__ - prev = __builtin__.__debug__ - setattr(__builtin__, '__debug__', 'sure') - setattr(__builtin__, '__debug__', prev) + import builtins + prev = builtins.__debug__ + setattr(builtins, '__debug__', 'sure') + setattr(builtins, '__debug__', prev) def test_argument_handling(self): # detect duplicate positional and keyword arguments diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index d1f9b1a9db..ae4687f17d 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -288,7 +288,7 @@ class ExceptionTests(unittest.TestCase): raise else: # Verify module name - self.assertEquals(type(e).__module__, '__builtin__') + self.assertEquals(type(e).__module__, 'builtins') # Verify no ref leaks in Exc_str() s = str(e) for checkArgName in expected: diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index 12a657cb78..a875272bd3 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -146,13 +146,13 @@ trggrkg zrffntr pngnybt yvoenel.''') t.install(str=True) eq(_('mullusk'), 'bacon') # Test installation of other methods - import __builtin__ + import builtins t.install(str=True, names=["gettext", "lgettext"]) eq(_, t.ugettext) - eq(__builtin__.gettext, t.ugettext) + eq(builtins.gettext, t.ugettext) eq(lgettext, t.lgettext) - del __builtin__.gettext - del __builtin__.lgettext + del builtins.gettext + del builtins.lgettext class GettextTestCase2(GettextBaseTest): diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 60a7ad1817..75e66ed9a1 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -29,7 +29,7 @@ modfile = normcase(modfile) def revise(filename, *args): return (normcase(filename),) + args -import __builtin__ +import builtins try: 1/0 @@ -197,7 +197,7 @@ class TestRetrievingSourceCode(GetSourceBase): # Do it again (check the caching isn't broken) self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod) # Check a builtin - self.assertEqual(inspect.getmodule(str), sys.modules["__builtin__"]) + self.assertEqual(inspect.getmodule(str), sys.modules["builtins"]) # Check filename override self.assertEqual(inspect.getmodule(None, modfile), mod) diff --git a/Lib/test/test_iterlen.py b/Lib/test/test_iterlen.py index afd7287aa7..93b77b606a 100644 --- a/Lib/test/test_iterlen.py +++ b/Lib/test/test_iterlen.py @@ -46,7 +46,7 @@ from test import test_support from itertools import repeat from collections import deque from UserList import UserList -from __builtin__ import len as _len +from builtins import len as _len n = 10 diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py index ddeee1a1b7..db117ef2a8 100644 --- a/Lib/test/test_pep352.py +++ b/Lib/test/test_pep352.py @@ -1,5 +1,5 @@ import unittest -import __builtin__ +import builtins import warnings from test.test_support import run_unittest import os @@ -23,7 +23,7 @@ class ExceptionClassTests(unittest.TestCase): def test_inheritance(self): # Make sure the inheritance hierarchy matches the documentation exc_set = set() - for object_ in __builtin__.__dict__.values(): + for object_ in builtins.__dict__.values(): try: if issubclass(object_, BaseException): exc_set.add(object_.__name__) @@ -35,7 +35,7 @@ class ExceptionClassTests(unittest.TestCase): try: superclass_name = inheritance_tree.readline().rstrip() try: - last_exc = getattr(__builtin__, superclass_name) + last_exc = getattr(builtins, superclass_name) except AttributeError: self.fail("base class %s not a built-in" % superclass_name) self.failUnless(superclass_name in exc_set, @@ -58,7 +58,7 @@ class ExceptionClassTests(unittest.TestCase): left_bracket = exc_name.index('[') exc_name = exc_name[:left_bracket-1] # cover space try: - exc = getattr(__builtin__, exc_name) + exc = getattr(builtins, exc_name) except AttributeError: self.fail("%s not a built-in exception" % exc_name) if last_depth < depth: diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 11bb674a34..4624ea6276 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -6,7 +6,7 @@ executing have not been removed. """ import unittest from test.test_support import TestSkipped, TestFailed, run_unittest, TESTFN -import __builtin__ +import builtins import os import sys import encodings @@ -162,7 +162,7 @@ class ImportSideEffectTests(unittest.TestCase): # as an absolute path. # Handled by abs__file__() site.abs__file__() - for module in (sys, os, __builtin__): + for module in (sys, os, builtins): try: self.failUnless(os.path.isabs(module.__file__), repr(module)) except AttributeError: @@ -187,18 +187,18 @@ class ImportSideEffectTests(unittest.TestCase): pass def test_setting_quit(self): - # 'quit' and 'exit' should be injected into __builtin__ - self.failUnless(hasattr(__builtin__, "quit")) - self.failUnless(hasattr(__builtin__, "exit")) + # 'quit' and 'exit' should be injected into builtins + self.failUnless(hasattr(builtins, "quit")) + self.failUnless(hasattr(builtins, "exit")) def test_setting_copyright(self): - # 'copyright' and 'credits' should be in __builtin__ - self.failUnless(hasattr(__builtin__, "copyright")) - self.failUnless(hasattr(__builtin__, "credits")) + # 'copyright' and 'credits' should be in builtins + self.failUnless(hasattr(builtins, "copyright")) + self.failUnless(hasattr(builtins, "credits")) def test_setting_help(self): - # 'help' should be set in __builtin__ - self.failUnless(hasattr(__builtin__, "help")) + # 'help' should be set in builtins + self.failUnless(hasattr(builtins, "help")) def test_aliasing_mbcs(self): if sys.platform == "win32": diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 767f3a803d..435a6968cb 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -15,22 +15,22 @@ class SysModuleTest(unittest.TestCase): sys.displayhook = self.orig_displayhook def test_original_displayhook(self): - import __builtin__ + import builtins out = io.StringIO() sys.stdout = out dh = sys.__displayhook__ self.assertRaises(TypeError, dh) - if hasattr(__builtin__, "_"): - del __builtin__._ + if hasattr(builtins, "_"): + del builtins._ dh(None) self.assertEqual(out.getvalue(), "") - self.assert_(not hasattr(__builtin__, "_")) + self.assert_(not hasattr(builtins, "_")) dh(42) self.assertEqual(out.getvalue(), "42\n") - self.assertEqual(__builtin__._, 42) + self.assertEqual(builtins._, 42) del sys.stdout self.assertRaises(RuntimeError, dh, 42) diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 36ea06782f..93e512601d 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -65,7 +65,7 @@ class TracebackCases(unittest.TestCase): err = traceback.format_exception_only(X, X()) self.assertEqual(len(err), 1) str_value = '<unprintable %s object>' % X.__name__ - if X.__module__ in ('__main__', '__builtin__'): + if X.__module__ in ('__main__', 'builtins'): str_name = X.__name__ else: str_name = '.'.join([X.__module__, X.__name__]) diff --git a/Lib/traceback.py b/Lib/traceback.py index 11ece25ca6..0c01ac3bc9 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -168,7 +168,7 @@ def format_exception_only(etype, value): stype = etype.__name__ smod = etype.__module__ - if smod not in ("__main__", "__builtin__"): + if smod not in ("__main__", "builtins"): stype = smod + '.' + stype if not issubclass(etype, SyntaxError): diff --git a/Lib/wave.py b/Lib/wave.py index eda3697144..8455522f8f 100644 --- a/Lib/wave.py +++ b/Lib/wave.py @@ -71,7 +71,7 @@ The close() method is called automatically when the class instance is destroyed. """ -import __builtin__ +import builtins __all__ = ["open", "openfp", "Error"] @@ -156,7 +156,7 @@ class Wave_read: def __init__(self, f): self._i_opened_the_file = None if isinstance(f, str): - f = __builtin__.open(f, 'rb') + f = builtins.open(f, 'rb') self._i_opened_the_file = f # else, assume it is an open file object already try: @@ -300,7 +300,7 @@ class Wave_write: def __init__(self, f): self._i_opened_the_file = None if isinstance(f, str): - f = __builtin__.open(f, 'wb') + f = builtins.open(f, 'wb') self._i_opened_the_file = f try: self.initfp(f) |