From 8b8f2ec560136a6b4bf91726aaaff2376a725cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Sat, 26 Mar 2011 07:22:01 +0100 Subject: [PATCH 01/15] Kill last reference to defunct module --- Doc/c-api/intro.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index e8b62dc5fc7..c008b5c93dd 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -511,13 +511,12 @@ interpreter can only be used after the interpreter has been initialized. module: builtins module: __main__ module: sys - module: exceptions triple: module; search; path single: path (in module sys) The basic initialization function is :cfunc:`Py_Initialize`. This initializes the table of loaded modules, and creates the fundamental modules -:mod:`builtins`, :mod:`__main__`, :mod:`sys`, and :mod:`exceptions`. It also +:mod:`builtins`, :mod:`__main__`, and :mod:`sys`. It also initializes the module search path (``sys.path``). .. index:: single: PySys_SetArgv() From 395ba35a9224339bdcaf20ad966ceaf084142444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 15 Apr 2011 23:34:31 +0200 Subject: [PATCH 02/15] Minor tweaks to a few comments in heapq --- Lib/heapq.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/heapq.py b/Lib/heapq.py index b74818e2ba7..cc61294cc8b 100644 --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -172,7 +172,7 @@ def heappushpop(heap, item): return item def heapify(x): - """Transform list into a heap, in-place, in O(len(heap)) time.""" + """Transform list into a heap, in-place, in O(len(x)) time.""" n = len(x) # Transform bottom-up. The largest index there's any point to looking at # is the largest with a child index in-range, so must have 2*i + 1 < n, @@ -363,7 +363,7 @@ def nsmallest(n, iterable, key=None): return [min(chain(head, it))] return [min(chain(head, it), key=key)] - # When n>=size, it's faster to use sort() + # When n>=size, it's faster to use sorted() try: size = len(iterable) except (TypeError, AttributeError): @@ -401,7 +401,7 @@ def nlargest(n, iterable, key=None): return [max(chain(head, it))] return [max(chain(head, it), key=key)] - # When n>=size, it's faster to use sort() + # When n>=size, it's faster to use sorted() try: size = len(iterable) except (TypeError, AttributeError): From 691840f2189d78e50e63ec04f5ce71b9d3049c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Thu, 14 Apr 2011 03:49:19 +0200 Subject: [PATCH 03/15] Fix improper tests in RegisterTestCase --- Lib/distutils/tests/test_register.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py index c712f56a788..cb72a115382 100644 --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -137,7 +137,7 @@ class RegisterTestCase(PyPIRCCommandTestCase): # let's see what the server received : we should # have 2 similar requests - self.assertTrue(self.conn.reqs, 2) + self.assertEqual(len(self.conn.reqs), 2) req1 = dict(self.conn.reqs[0].headers) req2 = dict(self.conn.reqs[1].headers) @@ -169,7 +169,7 @@ class RegisterTestCase(PyPIRCCommandTestCase): del register_module.input # we should have send a request - self.assertTrue(self.conn.reqs, 1) + self.assertEqual(len(self.conn.reqs), 1) req = self.conn.reqs[0] headers = dict(req.headers) self.assertEqual(headers['Content-length'], '608') @@ -187,7 +187,7 @@ class RegisterTestCase(PyPIRCCommandTestCase): del register_module.input # we should have send a request - self.assertTrue(self.conn.reqs, 1) + self.assertEqual(len(self.conn.reqs), 1) req = self.conn.reqs[0] headers = dict(req.headers) self.assertEqual(headers['Content-length'], '290') From e7d36fe0a6118a055b407f0651fed3cefc01e9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Sun, 17 Apr 2011 16:48:52 +0200 Subject: [PATCH 04/15] Prevent deprecation warning --- Lib/trace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/trace.py b/Lib/trace.py index 53c6150fd40..850369b9ff4 100644 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -688,7 +688,7 @@ def main(argv=None): for opt, val in opts: if opt == "--help": - usage(sys.stdout) + _usage(sys.stdout) sys.exit(0) if opt == "--version": From 2a83cc61d6bd96dc05008039703827ec0438cf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Sun, 17 Apr 2011 19:10:27 +0200 Subject: [PATCH 05/15] Add missing types to docstring of ast.literal_eval. The reST doc was updated but not the docstring. --- Lib/ast.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/ast.py b/Lib/ast.py index 72237ed9085..fb5adac8fd9 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -40,8 +40,8 @@ def literal_eval(node_or_string): """ Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following - Python literal structures: strings, numbers, tuples, lists, dicts, booleans, - and None. + Python literal structures: strings, bytes, numbers, tuples, lists, dicts, + sets, booleans, and None. """ _safe_names = {'None': None, 'True': True, 'False': False} if isinstance(node_or_string, str): From 87f3a9aac7f4b324f10b23adb1e79ad6b69117ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Sat, 16 Apr 2011 00:13:39 +0200 Subject: [PATCH 06/15] Fix double use of f.close(). The other one is in a finally block not seen in the diff, which I added in 3bf86785cd9c (for #10252). --- Lib/sysconfig.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index 685c84ea5ef..3b0ca85fbbc 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -694,7 +694,6 @@ def get_platform(): m = re.search( r'ProductUserVisibleVersion\s*' + r'(.*?)', f.read()) - f.close() if m is not None: macrelease = '.'.join(m.group(1).split('.')[:2]) # else: fall back to the default behaviour From a0b3c32c7a35422c1196824dce1a0c1f7f8969eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Sat, 16 Apr 2011 23:47:53 +0200 Subject: [PATCH 07/15] Advertise nesting directives for class/method and class/data combos. Also fix a typo and a misleading example (method used to describe function). --- Doc/documenting/markup.rst | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Doc/documenting/markup.rst b/Doc/documenting/markup.rst index 34a79d4372a..be7718d82e3 100644 --- a/Doc/documenting/markup.rst +++ b/Doc/documenting/markup.rst @@ -152,7 +152,7 @@ The directives are: Describes global data in a module, including both variables and values used as "defined constants." Class and object attributes are not documented - using this environment. + using this directive. .. describe:: exception @@ -165,7 +165,7 @@ The directives are: parameters, enclosing optional parameters in brackets. Default values can be given if it enhances clarity. For example:: - .. function:: Timer.repeat([repeat=3[, number=1000000]]) + .. function:: repeat([repeat=3[, number=1000000]]) Object methods are not documented using this directive. Bound object methods placed in the module namespace as part of the public interface of the module @@ -186,13 +186,30 @@ The directives are: Describes an object data attribute. The description should include information about the type of the data to be expected and whether it may be - changed directly. + changed directly. This directive should be nested in a class directive, + like in this example:: + + .. class:: Spam + + Description of the class. + + .. data:: ham + + Description of the attribute. + + If is also possible to document an attribute outside of a class directive, + for example if the documentation for different attributes and methods is + split in multiple sections. The class name should then be included + explicitly:: + + .. data:: Spam.eggs .. describe:: method Describes an object method. The parameters should not include the ``self`` parameter. The description should include similar information to that - described for ``function``. + described for ``function``. This method should be nested in a class + method, like in the example above. .. describe:: opcode From dcb22a39366f7bea8aa3359803ee32fe46debf58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Sun, 17 Apr 2011 14:27:07 +0200 Subject: [PATCH 08/15] Fix resource warning found manually --- Lib/distutils/command/sdist.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index 1118060cbb9..fdbebd7e0fc 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -294,17 +294,20 @@ class sdist(Command): join_lines=1, lstrip_ws=1, rstrip_ws=1, collapse_join=1) - while True: - line = template.readline() - if line is None: # end of file - break + try: + while True: + line = template.readline() + if line is None: # end of file + break - try: - self.filelist.process_template_line(line) - except DistutilsTemplateError as msg: - self.warn("%s, line %d: %s" % (template.filename, - template.current_line, - msg)) + try: + self.filelist.process_template_line(line) + except DistutilsTemplateError as msg: + self.warn("%s, line %d: %s" % (template.filename, + template.current_line, + msg)) + finally: + template.close() def prune_file_list(self): """Prune off branches that might slip into the file list as created From f8e1b607994028c826401c7f6f3637d9c797ed25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Wed, 20 Apr 2011 18:52:55 +0200 Subject: [PATCH 09/15] Add docstring to dbm.open --- Lib/dbm/__init__.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Lib/dbm/__init__.py b/Lib/dbm/__init__.py index 99c16379a95..57be17b4081 100644 --- a/Lib/dbm/__init__.py +++ b/Lib/dbm/__init__.py @@ -24,16 +24,8 @@ It has the following interface (key and data are strings): list = d.keys() # return a list of all existing keys (slow!) Future versions may change the order in which implementations are -tested for existence, add interfaces to other dbm-like +tested for existence, and add interfaces to other dbm-like implementations. - -The open function has an optional second argument. This can be 'r', -for read-only access, 'w', for read-write access of an existing -database, 'c' for read-write access to a new or existing database, and -'n' for read-write access to a new database. The default is 'r'. - -Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it -only if it doesn't exist; and 'n' always creates a new database. """ __all__ = ['open', 'whichdb', 'error', 'error'] @@ -54,7 +46,17 @@ _modules = {} error = (error, IOError) -def open(file, flag = 'r', mode = 0o666): +def open(file, flag='r', mode=0o666): + """Open or create database at path given by *file*. + + Optional argument *flag* can be 'r' (default) for read-only access, 'w' + for read-write access of an existing database, 'c' for read-write access + to a new or existing database, and 'n' for read-write access to a new + database. + + Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it + only if it doesn't exist; and 'n' always creates a new database. + """ global _defaultmod if _defaultmod is None: for name in _names: From 5c1a0c969d82670ba7aac7647b9828f4df85c1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Wed, 20 Apr 2011 19:11:12 +0200 Subject: [PATCH 10/15] Fix argument name in reST doc to match the code --- Doc/library/dbm.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/dbm.rst b/Doc/library/dbm.rst index c7c73475eb6..cbefc1aa118 100644 --- a/Doc/library/dbm.rst +++ b/Doc/library/dbm.rst @@ -30,9 +30,9 @@ the Oracle Berkeley DB. name, such as ``'dbm.ndbm'`` or ``'dbm.gnu'``. -.. function:: open(filename, flag='r', mode=0o666) +.. function:: open(file, flag='r', mode=0o666) - Open the database file *filename* and return a corresponding object. + Open the database file *file* and return a corresponding object. If the database file already exists, the :func:`whichdb` function is used to determine its type and the appropriate module is used; if it does not exist, From de579d4359e0088feb36bb4be080c2ab36cd9365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Thu, 21 Apr 2011 02:37:41 +0200 Subject: [PATCH 11/15] Add a space to make json doc a bit more readable --- Doc/library/json.rst | 2 +- Lib/json/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst index 6bb48e81ef5..48acaf19d6f 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -34,7 +34,7 @@ Encoding basic Python object hierarchies:: Compact encoding:: >>> import json - >>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':')) + >>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',', ':')) '[1,2,3,{"4":5,"6":7}]' Pretty printing:: diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py index a746f9cf9c9..6d88931dcbd 100644 --- a/Lib/json/__init__.py +++ b/Lib/json/__init__.py @@ -31,7 +31,7 @@ Encoding basic Python object hierarchies:: Compact encoding:: >>> import json - >>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':')) + >>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',', ':')) '[1,2,3,{"4":5,"6":7}]' Pretty printing:: From 2b9388a03325fa4452a8cb3b9df8a7fbb7302b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 22 Apr 2011 21:27:10 +0200 Subject: [PATCH 12/15] Fix weird executable name --- Doc/distutils/examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/distutils/examples.rst b/Doc/distutils/examples.rst index 6c2773874cd..e8d1ec99374 100644 --- a/Doc/distutils/examples.rst +++ b/Doc/distutils/examples.rst @@ -280,7 +280,7 @@ For example, if the :file:`setup.py` script is changed like this:: Where the long description is broken, ``check`` will be able to detect it by using the :mod:`docutils` parser:: - $ pythontrunk setup.py check --restructuredtext + $ python setup.py check --restructuredtext running check warning: check: Title underline too short. (line 2) warning: check: Could not finish the parsing. From b547148d163d54612528e0c4f2b133dc9ca7cb49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Sun, 24 Apr 2011 02:44:39 +0200 Subject: [PATCH 13/15] Fix indentation --- Doc/library/runpy.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/runpy.rst b/Doc/library/runpy.rst index f7c77f6b8d7..4df622cb1f8 100644 --- a/Doc/library/runpy.rst +++ b/Doc/library/runpy.rst @@ -49,7 +49,7 @@ The :mod:`runpy` module provides two functions: loader does not make filename information available, this variable is set to :const:`None`. - ``__cached__`` will be set to ``None``. + ``__cached__`` will be set to ``None``. ``__loader__`` is set to the :pep:`302` module loader used to retrieve the code for the module (This loader may be a wrapper around the standard From 08c9bd57f213bd7bf4d69567fe8d2305c0f4b9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Sun, 24 Apr 2011 02:59:02 +0200 Subject: [PATCH 14/15] Remove unneeded backslashes --- Doc/library/collections.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 1849e4ca0ad..d29bc175b44 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -205,14 +205,14 @@ counts, but the output will exclude results with counts of zero or less. * `Bag class `_ in Smalltalk. - * Wikipedia entry for `Multisets `_\. + * Wikipedia entry for `Multisets `_. * `C++ multisets `_ tutorial with examples. * For mathematical operations on multisets and their use cases, see *Knuth, Donald. The Art of Computer Programming Volume II, - Section 4.6.3, Exercise 19*\. + Section 4.6.3, Exercise 19*. * To enumerate all distinct multisets of a given size over a given set of elements, see :func:`itertools.combinations_with_replacement`. From ce4c4074f9322463fa714650c76f869ddcf2cb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Sun, 24 Apr 2011 03:31:37 +0200 Subject: [PATCH 15/15] =?UTF-8?q?The=20version*=20directives=20don?= =?UTF-8?q?=E2=80=99t=20work=20with=20a=20blank=20line=20between=20argumen?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Doc/c-api/object.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index afa08c9bc3c..d0d45ad0012 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -258,7 +258,6 @@ is considered sufficient for this determination. This is the equivalent of the Python expression ``hash(o)``. .. versionchanged:: 3.2 - The return type is now Py_hash_t. This is a signed integer the same size as Py_ssize_t.