summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2012-06-03 20:18:47 (GMT)
committerBarry Warsaw <barry@python.org>2012-06-03 20:18:47 (GMT)
commit409da157d7ff2a49892e20a94a3fc83475845d22 (patch)
tree734314ff314990b3f3b9bb6f8de2e2f4ee0b54dc /Doc
parent82ffabdfa4de985690c76fd7498a77e9604e1747 (diff)
downloadcpython-409da157d7ff2a49892e20a94a3fc83475845d22.zip
cpython-409da157d7ff2a49892e20a94a3fc83475845d22.tar.gz
cpython-409da157d7ff2a49892e20a94a3fc83475845d22.tar.bz2
Eric Snow's implementation of PEP 421.
Issue 14673: Add sys.implementation
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/sys.rst38
-rw-r--r--Doc/library/types.rst24
2 files changed, 62 insertions, 0 deletions
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index fd221fc..db5f374 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -616,6 +616,44 @@ always available.
Thus ``2.1.0a3`` is hexversion ``0x020100a3``.
+
+.. data:: implementation
+
+ An object containing the information about the implementation of the
+ currently running Python interpreter. Its attributes are the those
+ that all Python implementations must implement. They are described
+ below.
+
+ *name* is the implementation's identifier, like ``'cpython'``.
+
+ *version* is a named tuple, in the same format as
+ :data:`sys.version_info`. It represents the version of the Python
+ *implementation*. This has a distinct meaning from the specific
+ version of the Python *language* to which the currently running
+ interpreter conforms, which ``sys.version_info`` represents. For
+ example, for PyPy 1.8 ``sys.implementation.version`` might be
+ ``sys.version_info(1, 8, 0, 'final', 0)``, whereas ``sys.version_info``
+ would be ``sys.version_info(1, 8, 0, 'final', 0)``. For CPython they
+ are the same value, since it is the reference implementation.
+
+ *hexversion* is the implementation version in hexadecimal format, like
+ :data:`sys.hexversion`.
+
+ *cache_tag* is the tag used by the import machinery in the filenames of
+ cached modules. By convention, it would be a composite of the
+ implementation's name and version, like ``'cpython-33'``. However, a
+ Python implementation may use some other value if appropriate. If
+ ``cache_tag`` is set to ``None``, it indicates that module caching should
+ be disabled.
+
+ Regardless of its contents, :data:`sys.implementation` will not
+ change during a run of the interpreter, nor between implementation
+ versions. (It may change between Python language versions,
+ however.) See `PEP 421` for more information.
+
+ .. versionadded:: 3.3
+
+
.. data:: int_info
A :term:`struct sequence` that holds information about Python's internal
diff --git a/Doc/library/types.rst b/Doc/library/types.rst
index fc26afa..b60b195 100644
--- a/Doc/library/types.rst
+++ b/Doc/library/types.rst
@@ -194,3 +194,27 @@ Standard names are defined for the following types:
Return a new view of the underlying mapping's values.
+.. class:: SimpleNamespace
+
+ A simple :class:`object` subclass that provides attribute access to its
+ namespace, as well as a meaningful repr.
+
+ Unlike :class:`object`, with ``SimpleNamespace`` you can add and remove
+ attributes. If a ``SimpleNamespace`` object is initialized with keyword
+ arguments, those are directly added to the underlying namespace.
+
+ The type is roughly equivalent to the following code::
+
+ class SimpleNamespace:
+ def __init__(self, **kwargs):
+ self.__dict__.update(kwargs)
+ def __repr__(self):
+ keys = sorted(self.__dict__)
+ items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
+ return "{}({})".format(type(self).__name__, ", ".join(items))
+
+ ``SimpleNamespace`` may be useful as a replacement for ``class NS: pass``.
+ However, for a structured record type use :func:`~collections.namedtuple`
+ instead.
+
+ .. versionadded:: 3.3