From e801aa2a1d291635b3607bc424c639a992799254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 29 Jul 2011 17:50:58 +0200 Subject: Let the doc of __import__ link to importlib (#9254). importlib.import_module eschews a number of issues that __import__ has. Reviewed by Brett Cannon. (The docstring of __import__ was already updated in 3d490c3a019e, for #7397.) --- Doc/library/functions.rst | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index b766a2e..edff106 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1387,7 +1387,7 @@ are always available. They are listed here in alphabetical order. .. note:: This is an advanced function that is not needed in everyday Python - programming. + programming, unlike :func:`importlib.import_module`. This function is invoked by the :keyword:`import` statement. It can be replaced (by importing the :mod:`builtins` module and assigning to @@ -1437,15 +1437,8 @@ are always available. They are listed here in alphabetical order. names. If you simply want to import a module (potentially within a package) by name, - you can call :func:`__import__` and then look it up in :data:`sys.modules`:: - - >>> import sys - >>> name = 'foo.bar.baz' - >>> __import__(name) - - >>> baz = sys.modules[name] - >>> baz - + use :func:`importlib.import_module`. + .. rubric:: Footnotes -- cgit v0.12 From 63b18a4445a22d157b5ddf0677cc904356d83d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 29 Jul 2011 17:59:17 +0200 Subject: Add a link target for argparse.Namespace (#8982) --- Doc/library/argparse.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 61e1786..3db8fec 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -110,7 +110,7 @@ Parsing arguments :class:`ArgumentParser` parses args through the :meth:`~ArgumentParser.parse_args` method. This will inspect the command line, convert each arg to the appropriate type and then invoke the appropriate action. -In most cases, this means a simple namespace object will be built up from +In most cases, this means a simple :class:`Namespace` object will be built up from attributes parsed out of the command line:: >>> parser.parse_args(['--sum', '7', '-1', '42']) @@ -722,7 +722,7 @@ the Action API. The easiest way to do this is to extend * ``parser`` - The ArgumentParser object which contains this action. -* ``namespace`` - The namespace object that will be returned by +* ``namespace`` - The :class:`Namespace` object that will be returned by :meth:`~ArgumentParser.parse_args`. Most actions add an attribute to this object. @@ -1333,11 +1333,14 @@ interactive prompt:: The Namespace object ^^^^^^^^^^^^^^^^^^^^ -By default, :meth:`~ArgumentParser.parse_args` will return a new object of type -:class:`Namespace` where the necessary attributes have been set. This class is -deliberately simple, just an :class:`object` subclass with a readable string -representation. If you prefer to have dict-like view of the attributes, you -can use the standard Python idiom via :func:`vars`:: +.. class:: Namespace + + Simple class used by default by :meth:`~ArgumentParser.parse_args` to create + an object holding attributes and return it. + +This class is deliberately simple, just an :class:`object` subclass with a +readable string representation. If you prefer to have dict-like view of the +attributes, you can use the standard Python idiom, :func:`vars`:: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo') -- cgit v0.12 From fe1e298d8bbfbdfd1c2af74dbb74f47e2d04a6d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 29 Jul 2011 18:04:24 +0200 Subject: Document that atexit execution order is undefined (#9788) --- Doc/library/atexit.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/library/atexit.rst b/Doc/library/atexit.rst index cc1051b..5b87b94 100644 --- a/Doc/library/atexit.rst +++ b/Doc/library/atexit.rst @@ -9,7 +9,9 @@ The :mod:`atexit` module defines functions to register and unregister cleanup functions. Functions thus registered are automatically executed upon normal -interpreter termination. +interpreter termination. The order in which the functions are called is not +defined; if you have cleanup operations that depend on each other, you should +wrap them in a function and register that one. This keeps :mod:`atexit` simple. Note: the functions registered via this module are not called when the program is killed by a signal not handled by Python, when a Python fatal internal error -- cgit v0.12