mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
#1535: rename __builtin__ module to builtins.
This commit is contained in:
parent
87f9c53937
commit
1a3284ed69
70 changed files with 246 additions and 247 deletions
|
@ -1,13 +1,13 @@
|
|||
|
||||
:mod:`__builtin__` --- Built-in objects
|
||||
=======================================
|
||||
:mod:`builtins` --- Built-in objects
|
||||
====================================
|
||||
|
||||
.. module:: __builtin__
|
||||
.. module:: builtins
|
||||
:synopsis: The module that provides the built-in namespace.
|
||||
|
||||
|
||||
This module provides direct access to all 'built-in' identifiers of Python; for
|
||||
example, ``__builtin__.open`` is the full name for the built-in function
|
||||
example, ``builtins.open`` is the full name for the built-in function
|
||||
:func:`open`. See chapter :ref:`builtin`.
|
||||
|
||||
This module is not normally accessed explicitly by most applications, but can be
|
||||
|
@ -16,10 +16,10 @@ but in which the built-in of that name is also needed. For example, in a module
|
|||
that wants to implement an :func:`open` function that wraps the built-in
|
||||
:func:`open`, this module can be used directly::
|
||||
|
||||
import __builtin__
|
||||
import builtins
|
||||
|
||||
def open(path):
|
||||
f = __builtin__.open(path, 'r')
|
||||
f = builtins.open(path, 'r')
|
||||
return UpperCaser(f)
|
||||
|
||||
class UpperCaser:
|
|
@ -356,7 +356,7 @@ available. They are listed here in alphabetical order.
|
|||
dictionaries as global and local namespace. If the *globals* dictionary is
|
||||
present and lacks '__builtins__', the current globals are copied into *globals*
|
||||
before *expression* is parsed. This means that *expression* normally has full
|
||||
access to the standard :mod:`__builtin__` module and restricted environments are
|
||||
access to the standard :mod:`builtins` module and restricted environments are
|
||||
propagated. If the *locals* dictionary is omitted it defaults to the *globals*
|
||||
dictionary. If both dictionaries are omitted, the expression is executed in the
|
||||
environment where :keyword:`eval` is called. The return value is the result of
|
||||
|
@ -398,7 +398,7 @@ available. They are listed here in alphabetical order.
|
|||
|
||||
If the *globals* dictionary does not contain a value for the key
|
||||
``__builtins__``, a reference to the dictionary of the built-in module
|
||||
:mod:`__builtin__` is inserted under that key. That way you can control what
|
||||
:mod:`builtins` is inserted under that key. That way you can control what
|
||||
builtins are available to the executed code by inserting your own
|
||||
``__builtins__`` dictionary into *globals* before passing it to :func:`exec`.
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ This code is intended to be read, not executed. However, it does work
|
|||
|
||||
::
|
||||
|
||||
import sys, imp, __builtin__
|
||||
import sys, imp, builtins
|
||||
|
||||
# Replacement for __import__()
|
||||
def import_hook(name, globals=None, locals=None, fromlist=None):
|
||||
|
@ -218,12 +218,12 @@ This code is intended to be read, not executed. However, it does work
|
|||
|
||||
|
||||
# Save the original hooks
|
||||
original_import = __builtin__.__import__
|
||||
original_reload = __builtin__.reload
|
||||
original_import = builtins.__import__
|
||||
original_reload = builtins.reload
|
||||
|
||||
# Now install our hooks
|
||||
__builtin__.__import__ = import_hook
|
||||
__builtin__.reload = reload_hook
|
||||
builtins.__import__ = import_hook
|
||||
builtins.reload = reload_hook
|
||||
|
||||
.. index::
|
||||
module: knee
|
||||
|
|
|
@ -13,7 +13,7 @@ overview:
|
|||
.. toctree::
|
||||
|
||||
sys.rst
|
||||
__builtin__.rst
|
||||
builtins.rst
|
||||
__main__.rst
|
||||
warnings.rst
|
||||
contextlib.rst
|
||||
|
|
|
@ -55,7 +55,7 @@ Completer objects have the following method:
|
|||
Return the *state*th completion for *text*.
|
||||
|
||||
If called for *text* that doesn't include a period character (``'.'``), it will
|
||||
complete from names currently defined in :mod:`__main__`, :mod:`__builtin__` and
|
||||
complete from names currently defined in :mod:`__main__`, :mod:`builtins` and
|
||||
keywords (as defined by the :mod:`keyword` module).
|
||||
|
||||
If called for a dotted name, it will try to evaluate anything without obvious
|
||||
|
|
|
@ -46,7 +46,7 @@ The :mod:`runpy` module provides a single function:
|
|||
does not make filename information available, this variable is set to ``None``.
|
||||
|
||||
``__builtins__`` is automatically initialised with a reference to the top level
|
||||
namespace of the :mod:`__builtin__` module.
|
||||
namespace of the :mod:`builtins` module.
|
||||
|
||||
If the argument *alter_sys* is supplied and evaluates to ``True``, then
|
||||
``sys.argv[0]`` is updated with the value of ``__file__`` and
|
||||
|
|
|
@ -78,7 +78,7 @@ always available.
|
|||
.. function:: displayhook(value)
|
||||
|
||||
If *value* is not ``None``, this function prints it to ``sys.stdout``, and saves
|
||||
it in ``__builtin__._``.
|
||||
it in ``builtins._``.
|
||||
|
||||
``sys.displayhook`` is called on the result of evaluating an expression entered
|
||||
in an interactive Python session. The display of these values can be customized
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue