From a0dfa82eca0f4b9855b6e234f9b21e5d60c88a10 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 13 Nov 2009 02:25:08 +0000 Subject: Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75149 | gregory.p.smith | 2009-09-29 16:56:31 -0500 (Tue, 29 Sep 2009) | 3 lines Mention issue6972 in extractall docs about overwriting things outside of the supplied path. ........ r75260 | andrew.kuchling | 2009-10-05 16:24:20 -0500 (Mon, 05 Oct 2009) | 1 line Wording fix ........ r75261 | andrew.kuchling | 2009-10-05 16:24:35 -0500 (Mon, 05 Oct 2009) | 1 line Fix narkup ........ r75262 | andrew.kuchling | 2009-10-05 16:25:03 -0500 (Mon, 05 Oct 2009) | 1 line Document 'skip' parameter to constructor ........ r75263 | andrew.kuchling | 2009-10-05 16:25:35 -0500 (Mon, 05 Oct 2009) | 1 line Note side benefit of socket.create_connection() ........ r75265 | andrew.kuchling | 2009-10-05 17:31:11 -0500 (Mon, 05 Oct 2009) | 1 line Reword sentence ........ r75266 | andrew.kuchling | 2009-10-05 17:32:48 -0500 (Mon, 05 Oct 2009) | 1 line Use standard comma punctuation; reword some sentences in the docs ........ r75267 | andrew.kuchling | 2009-10-05 17:42:56 -0500 (Mon, 05 Oct 2009) | 1 line Backport r73983: Document the thousands separator. ........ r75292 | benjamin.peterson | 2009-10-08 22:11:36 -0500 (Thu, 08 Oct 2009) | 1 line death to old CVS keyword ........ r75300 | benjamin.peterson | 2009-10-09 16:48:14 -0500 (Fri, 09 Oct 2009) | 1 line fix some coding style ........ r75376 | benjamin.peterson | 2009-10-11 20:26:07 -0500 (Sun, 11 Oct 2009) | 1 line platform we don't care about ........ r75405 | neil.schemenauer | 2009-10-14 12:17:14 -0500 (Wed, 14 Oct 2009) | 4 lines Issue #1754094: Improve the stack depth calculation in the compiler. There should be no other effect than a small decrease in memory use. Patch by Christopher Tur Lesniewski-Laas. ........ r75429 | benjamin.peterson | 2009-10-14 20:47:28 -0500 (Wed, 14 Oct 2009) | 1 line pep8ify if blocks ........ r75430 | benjamin.peterson | 2009-10-14 20:49:37 -0500 (Wed, 14 Oct 2009) | 1 line use floor division and add a test that exercises the tabsize codepath ........ r75431 | benjamin.peterson | 2009-10-14 20:56:25 -0500 (Wed, 14 Oct 2009) | 1 line change test to what I intended ........ r75432 | benjamin.peterson | 2009-10-14 22:05:39 -0500 (Wed, 14 Oct 2009) | 1 line some cleanups ........ r75433 | benjamin.peterson | 2009-10-14 22:06:55 -0500 (Wed, 14 Oct 2009) | 1 line make inspect.isabstract() always return a boolean; add a test for it, too #7069 ........ r75437 | benjamin.peterson | 2009-10-15 10:44:46 -0500 (Thu, 15 Oct 2009) | 1 line only clear a module's __dict__ if the module is the only one with a reference to it #7140 ........ r75445 | vinay.sajip | 2009-10-16 09:06:44 -0500 (Fri, 16 Oct 2009) | 1 line Issue #7120: logging: Removed import of multiprocessing which is causing crash in GAE. ........ r75501 | antoine.pitrou | 2009-10-18 13:37:11 -0500 (Sun, 18 Oct 2009) | 3 lines Add a comment about unreachable code, and fix a typo ........ r75551 | benjamin.peterson | 2009-10-19 22:14:10 -0500 (Mon, 19 Oct 2009) | 1 line use property api ........ r75572 | benjamin.peterson | 2009-10-20 16:55:17 -0500 (Tue, 20 Oct 2009) | 1 line clarify buffer arg #7178 ........ r75589 | benjamin.peterson | 2009-10-21 21:26:47 -0500 (Wed, 21 Oct 2009) | 1 line whitespace ........ r75590 | benjamin.peterson | 2009-10-21 21:36:47 -0500 (Wed, 21 Oct 2009) | 1 line rewrite to be nice to other implementations ........ r75591 | benjamin.peterson | 2009-10-21 21:50:38 -0500 (Wed, 21 Oct 2009) | 4 lines rewrite for style, clarify, and comments Also, use the hasattr() like scheme of allowing BaseException exceptions through. ........ r75657 | antoine.pitrou | 2009-10-24 07:41:27 -0500 (Sat, 24 Oct 2009) | 3 lines Fix compilation error in debug mode. ........ r75742 | benjamin.peterson | 2009-10-26 17:51:16 -0500 (Mon, 26 Oct 2009) | 1 line use 'is' instead of id() ........ r75868 | benjamin.peterson | 2009-10-27 15:59:18 -0500 (Tue, 27 Oct 2009) | 1 line test expect base classes ........ r75952 | georg.brandl | 2009-10-29 15:38:32 -0500 (Thu, 29 Oct 2009) | 1 line Use the correct function name in docstring. ........ r75953 | georg.brandl | 2009-10-29 15:39:50 -0500 (Thu, 29 Oct 2009) | 1 line Remove mention of the old -X command line switch. ........ r75954 | georg.brandl | 2009-10-29 15:53:00 -0500 (Thu, 29 Oct 2009) | 1 line Use constants instead of magic integers for test result. Do not re-run with --verbose3 for environment changing tests. ........ r75955 | georg.brandl | 2009-10-29 15:54:03 -0500 (Thu, 29 Oct 2009) | 1 line Use a single style for all the docstrings in the math module. ........ r75956 | georg.brandl | 2009-10-29 16:16:34 -0500 (Thu, 29 Oct 2009) | 1 line I do not think the "railroad" program mentioned is still available. ........ r75957 | georg.brandl | 2009-10-29 16:44:56 -0500 (Thu, 29 Oct 2009) | 1 line Fix constant name. ........ r76057 | benjamin.peterson | 2009-11-02 09:06:45 -0600 (Mon, 02 Nov 2009) | 1 line prevent a rather unlikely segfault ........ r76105 | georg.brandl | 2009-11-04 01:38:12 -0600 (Wed, 04 Nov 2009) | 1 line #7259: show correct equivalent for operator.i* operations in docstring; fix minor issues in operator docs. ........ r76139 | benjamin.peterson | 2009-11-06 19:04:38 -0600 (Fri, 06 Nov 2009) | 1 line spelling ........ r76143 | georg.brandl | 2009-11-07 02:26:07 -0600 (Sat, 07 Nov 2009) | 1 line #7271: fix typo. ........ r76162 | benjamin.peterson | 2009-11-08 22:10:53 -0600 (Sun, 08 Nov 2009) | 1 line discuss how to use -p ........ r76223 | georg.brandl | 2009-11-12 02:29:46 -0600 (Thu, 12 Nov 2009) | 1 line Give the profile module a module directive. ........ --- Doc/distutils/apiref.rst | 2 +- Doc/distutils/examples.rst | 8 +-- Doc/library/2to3.rst | 8 +++ Doc/library/bdb.rst | 12 +++- Doc/library/io.rst | 4 +- Doc/library/operator.rst | 156 ++++++++++++++++++++++------------------- Doc/library/pdb.rst | 2 +- Doc/library/profile.rst | 2 + Doc/library/pty.rst | 12 ++-- Doc/library/tarfile.rst | 2 +- Doc/library/turtle.rst | 2 +- Doc/library/weakref.rst | 7 +- Doc/library/zipfile.rst | 7 ++ Doc/whatsnew/2.6.rst | 10 ++- Lib/distutils/command/check.py | 2 +- Lib/inspect.py | 2 +- Lib/test/regrtest.py | 66 +++++++++-------- Lib/test/test_ast.py | 8 +++ Lib/test/test_inspect.py | 22 ++++++ Lib/test/test_module.py | 8 +++ Lib/test/test_strptime.py | 15 ++-- Lib/test/test_threading.py | 4 +- Lib/test/test_tokenize.py | 18 +++++ Lib/tokenize.py | 33 +++++---- Lib/xml/__init__.py | 6 -- Misc/Porting | 3 +- Modules/_io/stringio.c | 3 - Modules/mathmodule.c | 36 +++++----- Modules/operator.c | 28 ++++---- Objects/descrobject.c | 29 ++++---- Objects/listobject.c | 10 ++- Objects/moduleobject.c | 5 +- Parser/tokenizer.c | 34 ++++++--- 33 files changed, 347 insertions(+), 219 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst index cdb32d3..69ec0de 100644 --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -1952,7 +1952,7 @@ This is described in more detail in :pep:`301`. The ``check`` command performs some tests on the meta-data of a package. -It makes sure for example that all required meta-data are provided through +For example, it verifies that all required meta-data are provided as the arguments passed to the :func:`setup` function. .. % todo diff --git a/Doc/distutils/examples.rst b/Doc/distutils/examples.rst index d5918a5..648063b 100644 --- a/Doc/distutils/examples.rst +++ b/Doc/distutils/examples.rst @@ -236,10 +236,10 @@ With exactly the same source tree layout, this extension can be put in the Checking a package ================== -The ``check`` command allows you to verify if your package meta-data are -meeting the minimum requirements to build a distribution. +The ``check`` command allows you to verify if your package meta-data +meet the minimum requirements to build a distribution. -To run it, just call it over your :file:`setup.py` script. If something is +To run it, just call it using your :file:`setup.py` script. If something is missing, ``check`` will display a warning. Let's take an example with a simple script:: @@ -252,7 +252,7 @@ Running the ``check`` command will display some warnings:: $ python setup.py check running check - warning: check: missing required meta-data: version ,url + warning: check: missing required meta-data: version, url warning: check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst index f37bb05..d9eb00c 100644 --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -86,6 +86,14 @@ document could also be refactored with this option. The :option:`-v` option enables output of more information on the translation process. +Since some print statements can be parsed as function calls or statements, 2to3 +cannot always read files containing the print function. When 2to3 detects the +presence of the ``from __future__ import print_function`` compiler directive, it +modifies its internal grammar to interpert :func:`print` as a function. This +change can also be enabled manually with the :option:`-p` flag. Use +:option:`-p` to run fixers on code that already has had its print statements +converted. + .. _2to3-fixers: diff --git a/Doc/library/bdb.rst b/Doc/library/bdb.rst index 3e5fcd6..d6d4ae2 100644 --- a/Doc/library/bdb.rst +++ b/Doc/library/bdb.rst @@ -62,14 +62,22 @@ The :mod:`bdb` module also defines two classes: * The breakpoint hit count. -.. class:: Bdb() +.. class:: Bdb(skip=None) - The :class:`Bdb` acts as a generic Python debugger base class. + The :class:`Bdb` class acts as a generic Python debugger base class. This class takes care of the details of the trace facility; a derived class should implement user interaction. The standard debugger class (:class:`pdb.Pdb`) is an example. + The *skip* argument, if given, must be an iterable of glob-style + module name patterns. The debugger will not step into frames that + originate in a module that matches one of these patterns. Whether a + frame is considered to originate in a certain module is determined + by the ``__name__`` in the frame globals. + + .. versionadded:: 2.7 + The *skip* argument. The following methods of :class:`Bdb` normally don't need to be overridden. diff --git a/Doc/library/io.rst b/Doc/library/io.rst index 5188b51..8fb984e 100644 --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -98,8 +98,8 @@ Module Interface *buffering* is an optional integer used to set the buffering policy. By default full buffering is on. Pass 0 to switch buffering off (only allowed - in binary mode), 1 to set line buffering, and an integer > 1 for full - buffering. + in binary mode), 1 to set line buffering, and an integer > 1 to indicate the + size of the buffer. *encoding* is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst index 24ace8b..175314e 100644 --- a/Doc/library/operator.rst +++ b/Doc/library/operator.rst @@ -104,6 +104,14 @@ The mathematical and bitwise operations are the most numerous: Return ``a // b``. +.. function:: index(a) + __index__(a) + + Return *a* converted to an integer. Equivalent to ``a.__index__()``. + + .. versionadded:: 2.5 + + .. function:: inv(obj) invert(obj) __inv__(obj) @@ -133,7 +141,7 @@ The mathematical and bitwise operations are the most numerous: .. function:: neg(obj) __neg__(obj) - Return *obj* negated. + Return *obj* negated (``-obj``). .. function:: or_(a, b) @@ -145,7 +153,7 @@ The mathematical and bitwise operations are the most numerous: .. function:: pos(obj) __pos__(obj) - Return *obj* positive. + Return *obj* positive (``+obj``). .. function:: pow(a, b) @@ -179,13 +187,7 @@ The mathematical and bitwise operations are the most numerous: Return the bitwise exclusive or of *a* and *b*. -.. function:: index(a) - __index__(a) - - Return *a* converted to an integer. Equivalent to ``a.__index__()``. - - -Operations which work with sequences include: +Operations which work with sequences (some of them with mappings too) include: .. function:: concat(a, b) __concat__(a, b) @@ -394,67 +396,77 @@ Mapping Operators to Functions This table shows how abstract operations correspond to operator symbols in the Python syntax and the functions in the :mod:`operator` module. -+-----------------------+-------------------------+---------------------------------+ -| Operation | Syntax | Function | -+=======================+=========================+=================================+ -| Addition | ``a + b`` | ``add(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` | -+-----------------------+-------------------------+---------------------------------+ -| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` | -+-----------------------+-------------------------+---------------------------------+ -| Division | ``a / b`` | ``truediv(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Division | ``a // b`` | ``floordiv(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Bitwise And | ``a & b`` | ``and_(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Bitwise Inversion | ``~ a`` | ``invert(a)`` | -+-----------------------+-------------------------+---------------------------------+ -| Bitwise Or | ``a | b`` | ``or_(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Exponentiation | ``a ** b`` | ``pow(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Identity | ``a is b`` | ``is_(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Identity | ``a is not b`` | ``is_not(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` | -+-----------------------+-------------------------+---------------------------------+ -| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` | -+-----------------------+-------------------------+---------------------------------+ -| Indexing | ``obj[k]`` | ``getitem(obj, k)`` | -+-----------------------+-------------------------+---------------------------------+ -| Left Shift | ``a << b`` | ``lshift(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Modulo | ``a % b`` | ``mod(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Multiplication | ``a * b`` | ``mul(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Negation (Arithmetic) | ``- a`` | ``neg(a)`` | -+-----------------------+-------------------------+---------------------------------+ -| Negation (Logical) | ``not a`` | ``not_(a)`` | -+-----------------------+-------------------------+---------------------------------+ -| Right Shift | ``a >> b`` | ``rshift(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| String Formatting | ``s % obj`` | ``mod(s, obj)`` | -+-----------------------+-------------------------+---------------------------------+ -| Subtraction | ``a - b`` | ``sub(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Truth Test | ``obj`` | ``truth(obj)`` | -+-----------------------+-------------------------+---------------------------------+ -| Ordering | ``a < b`` | ``lt(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Ordering | ``a <= b`` | ``le(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Equality | ``a == b`` | ``eq(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Difference | ``a != b`` | ``ne(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Ordering | ``a >= b`` | ``ge(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ -| Ordering | ``a > b`` | ``gt(a, b)`` | -+-----------------------+-------------------------+---------------------------------+ ++-----------------------+-------------------------+---------------------------------------+ +| Operation | Syntax | Function | ++=======================+=========================+=======================================+ +| Addition | ``a + b`` | ``add(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Division | ``a / b`` | ``div(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Division | ``a // b`` | ``floordiv(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Bitwise And | ``a & b`` | ``and_(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Bitwise Inversion | ``~ a`` | ``invert(a)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Bitwise Or | ``a | b`` | ``or_(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Exponentiation | ``a ** b`` | ``pow(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Identity | ``a is b`` | ``is_(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Identity | ``a is not b`` | ``is_not(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Indexing | ``obj[k]`` | ``getitem(obj, k)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Left Shift | ``a << b`` | ``lshift(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Modulo | ``a % b`` | ``mod(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Multiplication | ``a * b`` | ``mul(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Negation (Arithmetic) | ``- a`` | ``neg(a)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Negation (Logical) | ``not a`` | ``not_(a)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Positive | ``+ a`` | ``pos(a)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Right Shift | ``a >> b`` | ``rshift(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Sequence Repetition | ``seq * i`` | ``repeat(seq, i)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` | ++-----------------------+-------------------------+---------------------------------------+ +| Slicing | ``seq[i:j]`` | ``getitem(seq, slice(i, j))`` | ++-----------------------+-------------------------+---------------------------------------+ +| String Formatting | ``s % obj`` | ``mod(s, obj)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Subtraction | ``a - b`` | ``sub(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Truth Test | ``obj`` | ``truth(obj)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Ordering | ``a < b`` | ``lt(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Ordering | ``a <= b`` | ``le(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Equality | ``a == b`` | ``eq(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Difference | ``a != b`` | ``ne(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Ordering | ``a >= b`` | ``ge(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ +| Ordering | ``a > b`` | ``gt(a, b)`` | ++-----------------------+-------------------------+---------------------------------------+ diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index 96b524d..9a0c00e 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -55,7 +55,7 @@ insert :: import pdb; pdb.set_trace() at the location you want to break into the debugger. You can then step through -the code following this statement, and continue running without debugger using +the code following this statement, and continue running without the debugger using the ``c`` command. The typical usage to inspect a crashed program is:: diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst index e465b56..f7df0b5 100644 --- a/Doc/library/profile.rst +++ b/Doc/library/profile.rst @@ -6,6 +6,8 @@ The Python Profilers .. sectionauthor:: James Roskind +.. module:: profile + :synopsis: Python source profiler. .. index:: single: InfoSeek Corporation diff --git a/Doc/library/pty.rst b/Doc/library/pty.rst index ac965ff..d039fdf 100644 --- a/Doc/library/pty.rst +++ b/Doc/library/pty.rst @@ -2,8 +2,8 @@ ======================================== .. module:: pty - :platform: IRIX, Linux - :synopsis: Pseudo-Terminal Handling for SGI and Linux. + :platform: Linux + :synopsis: Pseudo-Terminal Handling for Linux. .. moduleauthor:: Steen Lumholt .. sectionauthor:: Moshe Zadka @@ -13,8 +13,8 @@ concept: starting another process and being able to write to and read from its controlling terminal programmatically. Because pseudo-terminal handling is highly platform dependent, there is code to -do it only for SGI and Linux. (The Linux code is supposed to work on other -platforms, but hasn't been tested yet.) +do it only for Linux. (The Linux code is supposed to work on other platforms, +but hasn't been tested yet.) The :mod:`pty` module defines the following functions: @@ -31,8 +31,8 @@ The :mod:`pty` module defines the following functions: .. function:: openpty() Open a new pseudo-terminal pair, using :func:`os.openpty` if possible, or - emulation code for SGI and generic Unix systems. Return a pair of file - descriptors ``(master, slave)``, for the master and the slave end, respectively. + emulation code for generic Unix systems. Return a pair of file descriptors + ``(master, slave)``, for the master and the slave end, respectively. .. function:: spawn(argv[, master_read[, stdin_read]]) diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst index 1f53037..4d0a995 100644 --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -365,7 +365,7 @@ object, see :ref:`tarinfo-objects` for details. value. Depending on this value the respective file is either excluded (:const:`True`) or added (:const:`False`). If *filter* is specified it must be a function that takes a :class:`TarInfo` object argument and returns the - changed TarInfo object. If it instead returns :const:`None` the TarInfo + changed :class:`TarInfo` object. If it instead returns :const:`None` the :class:`TarInfo` object will be excluded from the archive. See :ref:`tar-examples` for an example. diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index d70550a..d947186 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -2023,7 +2023,7 @@ The public classes of the module :mod:`turtle` Subclass of TurtleScreen, with :ref:`four methods added `. -.. class:: ScrolledCavas(master) +.. class:: ScrolledCanvas(master) :param master: some Tkinter widget to contain the ScrolledCanvas, i.e. a Tkinter-canvas with scrollbars added diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst index 685d207..2aa49e3 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -72,10 +72,9 @@ support weak references but can add support through subclassing:: obj = Dict(red=1, green=2, blue=3) # this object is weak referenceable -.. impl-detail:: - - Other built-in types such as :class:`tuple` and :class:`long` do not support - weak references even when subclassed. +Other built-in types such as :class:`tuple` and :class:`long` do not support +weak references even when subclassed (This is an implementation detail and may +be different across various Python implementations.). Extension types can easily be made to support weak references; see :ref:`weakref-support`. diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst index a7fb842..ae8751e 100644 --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -197,6 +197,13 @@ ZipFile Objects be a subset of the list returned by :meth:`namelist`. *pwd* is the password used for encrypted files. + .. warning:: + + Never extract archives from untrusted sources without prior inspection. + It is possible that files are created outside of *path*, e.g. members + that have absolute filenames starting with ``"/"`` or filenames with two + dots ``".."``. + .. method:: ZipFile.printdir() diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst index 27d8e5c..8b71153 100644 --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -2416,9 +2416,13 @@ changes, or look through the Subversion logs for all the details. environments. TIPC addresses are 4- or 5-tuples. (Contributed by Alberto Bertogli; :issue:`1646`.) - A new function, :func:`create_connection`, takes an address - and connects to it using an optional timeout value, returning - the connected socket object. + A new function, :func:`create_connection`, takes an address and + connects to it using an optional timeout value, returning the + connected socket object. This function also looks up the address's + type and connects to it using IPv4 or IPv6 as appropriate. Changing + your code to use :func:`create_connection` instead of + ``socket(socket.AF_INET, ...)`` may be all that's required to make + your code work with IPv6. * The base classes in the :mod:`SocketServer` module now support calling a :meth:`handle_timeout` method after a span of inactivity diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py index 9a8fca1..12844cb 100644 --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -92,7 +92,7 @@ class check(Command): missing.append(attr) if missing: - self.warn("missing required meta-data: %s" % ' ,'.join(missing)) + self.warn("missing required meta-data: %s" % ', '.join(missing)) if metadata.author: if not metadata.author_email: self.warn("missing meta-data: if 'author' supplied, " + diff --git a/Lib/inspect.py b/Lib/inspect.py index 1f1b7f9..c489502 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -238,7 +238,7 @@ def isroutine(object): def isabstract(object): """Return true if the object is an abstract base class (ABC).""" - return isinstance(object, type) and object.__flags__ & TPFLAGS_IS_ABSTRACT + return bool(isinstance(object, type) and object.__flags__ & TPFLAGS_IS_ABSTRACT) def getmembers(object, predicate=None): """Return all members of an object as (name, value) pairs sorted by name. diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 75a74fa..9fb0692 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -193,6 +193,14 @@ if sys.platform == 'darwin': newsoft = min(hard, max(soft, 1024*2048)) resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard)) +# Test result constants. +PASSED = 1 +FAILED = 0 +ENV_CHANGED = -1 +SKIPPED = -2 +RESOURCE_DENIED = -3 +INTERRUPTED = -4 + from test import support RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', @@ -352,7 +360,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, try: result = runtest(*args, **kwargs) except BaseException as e: - result = -4, e.__class__.__name__ + result = INTERRUPTED, e.__class__.__name__ sys.stdout.flush() print() # Force a newline (just in case) print(json.dumps(result)) @@ -443,19 +451,18 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, def accumulate_result(test, result): ok, test_time = result test_times.append((test_time, test)) - if ok > 0: + if ok == PASSED: good.append(test) - return 'good' - elif -2 < ok <= 0: + elif ok == FAILED: bad.append(test) - if ok == -1: - environment_changed.append(test) - return 'bad' - else: + elif ok == ENV_CHANGED: + bad.append(test) + environment_changed.append(test) + elif ok == SKIPPED: skipped.append(test) - if ok == -3: - resource_denieds.append(test) - return 'skipped' + elif ok == RESOURCE_DENIED: + skipped.append(test) + resource_denieds.append(test) if use_mp: from threading import Thread @@ -511,7 +518,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, print(stdout) if stderr: print(stderr, file=sys.stderr) - if result[0] == -4: + if result[0] == INTERRUPTED: assert result[1] == 'KeyboardInterrupt' pending.clear() raise KeyboardInterrupt # What else? @@ -532,8 +539,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, try: result = runtest(test, verbose, quiet, testdir, huntrleaks, debug) - which = accumulate_result(test, result) - if verbose3 and which == 'bad': + accumulate_result(test, result) + if verbose3 and result[0] == FAILED: print("Re-running test {} in verbose mode".format(test)) runtest(test, True, quiet, testdir, huntrleaks, debug) except KeyboardInterrupt: @@ -679,15 +686,14 @@ def runtest(test, verbose, quiet, testdir -- test directory huntrleaks -- run multiple times to test for leaks; requires a debug build; a triple corresponding to -R's three arguments - debug -- if true, print tracebacks for failed tests regardless of - verbose setting - Return: - -4 KeyboardInterrupt when run under -j - -3 test skipped because resource denied - -2 test skipped for some other reason - -1 test failed because it changed the execution environment - 0 test failed - 1 test passed + + Returns one of the test result constants: + INTERRUPTED KeyboardInterrupt when run under -j + RESOURCE_DENIED test skipped because resource denied + SKIPPED test skipped for some other reason + ENV_CHANGED test failed because it changed the execution environment + FAILED test failed + PASSED test passed """ support.verbose = verbose # Tell tests to be moderately quiet @@ -843,18 +849,18 @@ def runtest_inner(test, verbose, quiet, if not quiet: print(test, "skipped --", msg) sys.stdout.flush() - return -3, test_time + return RESOURCE_DENIED, test_time except unittest.SkipTest as msg: if not quiet: print(test, "skipped --", msg) sys.stdout.flush() - return -2, test_time + return SKIPPED, test_time except KeyboardInterrupt: raise except support.TestFailed as msg: print("test", test, "failed --", msg) sys.stdout.flush() - return 0, test_time + return FAILED, test_time except: type, value = sys.exc_info()[:2] print("test", test, "crashed --", str(type) + ":", value) @@ -862,13 +868,13 @@ def runtest_inner(test, verbose, quiet, if verbose or debug: traceback.print_exc(file=sys.stdout) sys.stdout.flush() - return 0, test_time + return FAILED, test_time else: if refleak: - return 0, test_time + return FAILED, test_time if environment.changed: - return -1, test_time - return 1, test_time + return ENV_CHANGED, test_time + return PASSED, test_time def cleanup_test_droppings(testname, verbose): import shutil diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 0a832c4..07697ac 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -154,6 +154,14 @@ class AST_Tests(unittest.TestCase): im = ast.parse("from . import y").body[0] self.assertIsNone(im.module) + def test_base_classes(self): + self.assertTrue(issubclass(ast.For, ast.stmt)) + self.assertTrue(issubclass(ast.Name, ast.expr)) + self.assertTrue(issubclass(ast.stmt, ast.AST)) + self.assertTrue(issubclass(ast.expr, ast.AST)) + self.assertTrue(issubclass(ast.comprehension, ast.AST)) + self.assertTrue(issubclass(ast.Gt, ast.AST)) + def test_nodeclasses(self): x = ast.BinOp(1, 2, 3, lineno=0) self.assertEquals(x.left, 1) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index c1df23e..9dba30d 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -120,6 +120,28 @@ class TestPredicates(IsTestBase): self.assertTrue('a' in members) self.assertTrue('b' not in members) + def test_isabstract(self): + from abc import ABCMeta, abstractmethod + + class AbstractClassExample(metaclass=ABCMeta): + + @abstractmethod + def foo(self): + pass + + class ClassExample(AbstractClassExample): + def foo(self): + pass + + a = ClassExample() + + # Test general behaviour. + self.assertTrue(inspect.isabstract(AbstractClassExample)) + self.assertFalse(inspect.isabstract(ClassExample)) + self.assertFalse(inspect.isabstract(a)) + self.assertFalse(inspect.isabstract(int)) + self.assertFalse(inspect.isabstract(5)) + class TestInterpreterStack(IsTestBase): def __init__(self, *args, **kwargs): diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py index 0e56290..21ddc9a 100644 --- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -55,6 +55,14 @@ class ModuleTests(unittest.TestCase): {"__name__": "foo", "__doc__": "foodoc", "bar": 42}) self.assertTrue(foo.__dict__ is d) + def test_dont_clear_dict(self): + # See issue 7140. + def f(): + foo = ModuleType("foo") + foo.bar = 4 + return foo + self.assertEqual(f().__dict__["bar"], 4) + def test_main(): run_unittest(ModuleTests) diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py index fb60ee4..9008717 100644 --- a/Lib/test/test_strptime.py +++ b/Lib/test/test_strptime.py @@ -493,9 +493,9 @@ class CacheTests(unittest.TestCase): _strptime._strptime_time("10", "%d") _strptime._strptime_time("2005", "%Y") _strptime._TimeRE_cache.locale_time.lang = "Ni" - original_time_re = id(_strptime._TimeRE_cache) + original_time_re = _strptime._TimeRE_cache _strptime._strptime_time("10", "%d") - self.assertNotEqual(original_time_re, id(_strptime._TimeRE_cache)) + self.assertIsNot(original_time_re, _strptime._TimeRE_cache) self.assertEqual(len(_strptime._regex_cache), 1) def test_regex_cleanup(self): @@ -514,11 +514,10 @@ class CacheTests(unittest.TestCase): def test_new_localetime(self): # A new LocaleTime instance should be created when a new TimeRE object # is created. - locale_time_id = id(_strptime._TimeRE_cache.locale_time) + locale_time_id = _strptime._TimeRE_cache.locale_time _strptime._TimeRE_cache.locale_time.lang = "Ni" _strptime._strptime_time("10", "%d") - self.assertNotEqual(locale_time_id, - id(_strptime._TimeRE_cache.locale_time)) + self.assertIsNot(locale_time_id, _strptime._TimeRE_cache.locale_time) def test_TimeRE_recreation(self): # The TimeRE instance should be recreated upon changing the locale. @@ -530,15 +529,15 @@ class CacheTests(unittest.TestCase): try: _strptime._strptime_time('10', '%d') # Get id of current cache object. - first_time_re_id = id(_strptime._TimeRE_cache) + first_time_re = _strptime._TimeRE_cache try: # Change the locale and force a recreation of the cache. locale.setlocale(locale.LC_TIME, ('de_DE', 'UTF8')) _strptime._strptime_time('10', '%d') # Get the new cache object's id. - second_time_re_id = id(_strptime._TimeRE_cache) + second_time_re = _strptime._TimeRE_cache # They should not be equal. - self.assertNotEqual(first_time_re_id, second_time_re_id) + self.assertIsNot(first_time_re, second_time_re) # Possible test locale is not supported while initial locale is. # If this is the case just suppress the exception and fall-through # to the reseting to the original locale. diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 330a2c5..c5d8d79 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -185,11 +185,13 @@ class ThreadTests(BaseTestCase): except AsyncExc: pass else: + # This code is unreachable but it reflects the intent. If we wanted + # to be smarter the above loop wouldn't be infinite. self.fail("AsyncExc not raised") try: self.assertEqual(result, 1) # one thread state modified except UnboundLocalError: - # The exception was raised to quickly for us to get the result. + # The exception was raised too quickly for us to get the result. pass # `worker_started` is set by the thread when it's inside a try/except diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index ba705ba..7b91ab2 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -531,6 +531,24 @@ pass the '-ucompiler' option to process the full directory. ... break ... else: True True + +Evil tabs + >>> dump_tokens("def f():\\n\\tif x\\n \\tpass") + ENCODING 'utf-8' (0, 0) (0, 0) + NAME 'def' (1, 0) (1, 3) + NAME 'f' (1, 4) (1, 5) + OP '(' (1, 5) (1, 6) + OP ')' (1, 6) (1, 7) + OP ':' (1, 7) (1, 8) + NEWLINE '\\n' (1, 8) (1, 9) + INDENT '\\t' (2, 0) (2, 1) + NAME 'if' (2, 1) (2, 3) + NAME 'x' (2, 4) (2, 5) + NEWLINE '\\n' (2, 5) (2, 6) + INDENT ' \\t' (3, 0) (3, 9) + NAME 'pass' (3, 9) (3, 13) + DEDENT '' (4, 0) (4, 0) + DEDENT '' (4, 0) (4, 0) """ from test import support diff --git a/Lib/tokenize.py b/Lib/tokenize.py index fb58c6b..9d2a6bb 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -23,15 +23,15 @@ __author__ = 'Ka-Ping Yee ' __credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, ' 'Skip Montanaro, Raymond Hettinger, Trent Nelson, ' 'Michael Foord') - import re, string, sys from token import * from codecs import lookup, BOM_UTF8 cookie_re = re.compile("coding[:=]\s*([-\w.]+)") import token -__all__ = [x for x in dir(token) if x[0] != '_'] + ["COMMENT", "tokenize", - "detect_encoding", "NL", "untokenize", "ENCODING", "TokenInfo"] +__all__ = [x for x in dir(token) if not x.startswith("_")] +__all__.extend(["COMMENT", "tokenize", "detect_encoding", "NL", "untokenize", + "ENCODING", "TokenInfo"]) del token COMMENT = N_TOKENS @@ -407,7 +407,7 @@ def _tokenize(readline, encoding): if encoding is not None: line = line.decode(encoding) - lnum = lnum + 1 + lnum += 1 pos, max = 0, len(line) if contstr: # continued string @@ -435,12 +435,17 @@ def _tokenize(readline, encoding): if not line: break column = 0 while pos < max: # measure leading whitespace - if line[pos] == ' ': column = column + 1 - elif line[pos] == '\t': column = (column/tabsize + 1)*tabsize - elif line[pos] == '\f': column = 0 - else: break - pos = pos + 1 - if pos == max: break + if line[pos] == ' ': + column += 1 + elif line[pos] == '\t': + column = (column//tabsize + 1)*tabsize + elif line[pos] == '\f': + column = 0 + else: + break + pos += 1 + if pos == max: + break if line[pos] in '#\r\n': # skip comments or blank lines if line[pos] == '#': @@ -516,13 +521,15 @@ def _tokenize(readline, encoding): elif initial == '\\': # continued stmt continued = 1 else: - if initial in '([{': parenlev = parenlev + 1 - elif initial in ')]}': parenlev = parenlev - 1 + if initial in '([{': + parenlev += 1 + elif initial in ')]}': + parenlev -= 1 yield TokenInfo(OP, token, spos, epos, line) else: yield TokenInfo(ERRORTOKEN, line[pos], (lnum, pos), (lnum, pos+1), line) - pos = pos + 1 + pos += 1 for indent in indents[1:]: # pop remaining indent levels yield TokenInfo(DEDENT, '', (lnum, 0), (lnum, 0), '') diff --git a/Lib/xml/__init__.py b/Lib/xml/__init__.py index fa5e8cd..deed983 100644 --- a/Lib/xml/__init__.py +++ b/Lib/xml/__init__.py @@ -19,12 +19,6 @@ etree -- The ElementTree XML library. This is a subset of the full __all__ = ["dom", "parsers", "sax", "etree"] -# When being checked-out without options, this has the form -# "Revision: x.y " -# When exported using -kv, it is "x.y". -__version__ = "$Revision$".split()[-2:][0] - - _MINIMUM_XMLPLUS_VERSION = (0, 8, 4) diff --git a/Misc/Porting b/Misc/Porting index 1b94f14..ec9cf1f 100644 --- a/Misc/Porting +++ b/Misc/Porting @@ -31,8 +31,7 @@ target platform. Forget about the posix module for now -- simply take it out of the config.c file. Bang on it until you get a >>> prompt. (You may have to disable the -importing of "site.py" and "exceptions.py" by passing -X and -S -options. +importing of "site.py" by passing the -S options.) Then bang on it until it executes very simple Python statements. diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c index ad9730d..c19c4c0 100644 --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -600,9 +600,6 @@ stringio_init(stringio *self, PyObject *args, PyObject *kwds) assert((newline != NULL && newline_obj != Py_None) || (newline == NULL && newline_obj == Py_None)); - assert((newline != NULL && newline_obj != Py_None) || - (newline == NULL && newline_obj == Py_None)); - if (newline) { self->readnl = PyUnicode_FromString(newline); if (self->readnl == NULL) diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 249c227..052fca1 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -661,7 +661,7 @@ PyDoc_STRVAR(math_ceil_doc, "This is the smallest integral value >= x."); FUNC2(copysign, copysign, - "copysign(x,y)\n\nReturn x with the sign of y.") + "copysign(x, y)\n\nReturn x with the sign of y.") FUNC1(cos, cos, 0, "cos(x)\n\nReturn the cosine of x (measured in radians).") FUNC1(cosh, cosh, 1, @@ -695,8 +695,8 @@ PyDoc_STRVAR(math_floor_doc, FUNC1A(gamma, m_tgamma, "gamma(x)\n\nGamma function at x.") FUNC1(log1p, log1p, 1, - "log1p(x)\n\nReturn the natural logarithm of 1+x (base e).\n\ - The result is computed in a way which is accurate for x near zero.") + "log1p(x)\n\nReturn the natural logarithm of 1+x (base e).\n" + "The result is computed in a way which is accurate for x near zero.") FUNC1(sin, sin, 0, "sin(x)\n\nReturn the sine of x (measured in radians).") FUNC1(sinh, sinh, 1, @@ -925,7 +925,7 @@ _fsum_error: #undef NUM_PARTIALS PyDoc_STRVAR(math_fsum_doc, -"sum(iterable)\n\n\ +"fsum(iterable)\n\n\ Return an accurate floating point sum of values in the iterable.\n\ Assumes IEEE-754 floating point arithmetic."); @@ -1101,7 +1101,8 @@ math_ldexp(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_ldexp_doc, -"ldexp(x, i) -> x * (2**i)"); +"ldexp(x, i)\n\n\ +Return x * (2**i)."); static PyObject * math_modf(PyObject *self, PyObject *arg) @@ -1192,7 +1193,8 @@ math_log(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_log_doc, -"log(x[, base]) -> the logarithm of x to the given base.\n\ +"log(x[, base])\n\n\ +Return the logarithm of x to the given base.\n\ If the base not specified, returns the natural logarithm (base e) of x."); static PyObject * @@ -1202,7 +1204,7 @@ math_log10(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_log10_doc, -"log10(x) -> the base 10 logarithm of x."); +"log10(x)\n\nReturn the base 10 logarithm of x."); static PyObject * math_fmod(PyObject *self, PyObject *args) @@ -1235,7 +1237,7 @@ math_fmod(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_fmod_doc, -"fmod(x,y)\n\nReturn fmod(x, y), according to platform C." +"fmod(x, y)\n\nReturn fmod(x, y), according to platform C." " x % y may differ."); static PyObject * @@ -1277,7 +1279,7 @@ math_hypot(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_hypot_doc, -"hypot(x,y)\n\nReturn the Euclidean distance, sqrt(x*x + y*y)."); +"hypot(x, y)\n\nReturn the Euclidean distance, sqrt(x*x + y*y)."); /* pow can't use math_2, but needs its own wrapper: the problem is that an infinite result can arise either as a result of overflow @@ -1364,7 +1366,7 @@ math_pow(PyObject *self, PyObject *args) } PyDoc_STRVAR(math_pow_doc, -"pow(x,y)\n\nReturn x**y (x to the power of y)."); +"pow(x, y)\n\nReturn x**y (x to the power of y)."); static const double degToRad = Py_MATH_PI / 180.0; static const double radToDeg = 180.0 / Py_MATH_PI; @@ -1379,7 +1381,8 @@ math_degrees(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_degrees_doc, -"degrees(x) -> converts angle x from radians to degrees"); +"degrees(x)\n\n\ +Convert angle x from radians to degrees."); static PyObject * math_radians(PyObject *self, PyObject *arg) @@ -1391,7 +1394,8 @@ math_radians(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_radians_doc, -"radians(x) -> converts angle x from degrees to radians"); +"radians(x)\n\n\ +Convert angle x from degrees to radians."); static PyObject * math_isnan(PyObject *self, PyObject *arg) @@ -1403,8 +1407,8 @@ math_isnan(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_isnan_doc, -"isnan(x) -> bool\n\ -Checks if float x is not a number (NaN)"); +"isnan(x) -> bool\n\n\ +Check if float x is not a number (NaN)."); static PyObject * math_isinf(PyObject *self, PyObject *arg) @@ -1416,8 +1420,8 @@ math_isinf(PyObject *self, PyObject *arg) } PyDoc_STRVAR(math_isinf_doc, -"isinf(x) -> bool\n\ -Checks if float x is infinite (positive or negative)"); +"isinf(x) -> bool\n\n\ +Check if float x is infinite (positive or negative)."); static PyMethodDef math_methods[] = { {"acos", math_acos, METH_O, math_acos_doc}, diff --git a/Modules/operator.c b/Modules/operator.c index 0ba8b09..85d662d 100644 --- a/Modules/operator.c +++ b/Modules/operator.c @@ -7,7 +7,7 @@ PyDoc_STRVAR(operator_doc, This module exports a set of functions implemented in C corresponding\n\ to the intrinsic operators of Python. For example, operator.add(x, y)\n\ is equivalent to the expression x+y. The function names are those\n\ -used for special class methods; variants without leading and trailing\n\ +used for special methods; variants without leading and trailing\n\ '__' are also provided for convenience."); #define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \ @@ -197,21 +197,21 @@ spam2o(not_,__not__, "not_(a) -- Same as not a.") spam2(and_,__and__, "and_(a, b) -- Same as a & b.") spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.") spam2(or_,__or__, "or_(a, b) -- Same as a | b.") -spam2(iadd,__iadd__, "iadd(a, b) -- Same as a += b.") -spam2(isub,__isub__, "isub(a, b) -- Same as a -= b.") -spam2(imul,__imul__, "imul(a, b) -- Same as a *= b.") -spam2(ifloordiv,__ifloordiv__, "ifloordiv(a, b) -- Same as a //= b.") -spam2(itruediv,__itruediv__, "itruediv(a, b) -- Same as a /= b.") -spam2(imod,__imod__, "imod(a, b) -- Same as a %= b.") -spam2(ilshift,__ilshift__, "ilshift(a, b) -- Same as a <<= b.") -spam2(irshift,__irshift__, "irshift(a, b) -- Same as a >>= b.") -spam2(iand,__iand__, "iand(a, b) -- Same as a &= b.") -spam2(ixor,__ixor__, "ixor(a, b) -- Same as a ^= b.") -spam2(ior,__ior__, "ior(a, b) -- Same as a |= b.") +spam2(iadd,__iadd__, "a = iadd(a, b) -- Same as a += b.") +spam2(isub,__isub__, "a = isub(a, b) -- Same as a -= b.") +spam2(imul,__imul__, "a = imul(a, b) -- Same as a *= b.") +spam2(ifloordiv,__ifloordiv__, "a = ifloordiv(a, b) -- Same as a //= b.") +spam2(itruediv,__itruediv__, "a = itruediv(a, b) -- Same as a /= b") +spam2(imod,__imod__, "a = imod(a, b) -- Same as a %= b.") +spam2(ilshift,__ilshift__, "a = ilshift(a, b) -- Same as a <<= b.") +spam2(irshift,__irshift__, "a = irshift(a, b) -- Same as a >>= b.") +spam2(iand,__iand__, "a = iand(a, b) -- Same as a &= b.") +spam2(ixor,__ixor__, "a = ixor(a, b) -- Same as a ^= b.") +spam2(ior,__ior__, "a = ior(a, b) -- Same as a |= b.") spam2(concat,__concat__, "concat(a, b) -- Same as a + b, for a and b sequences.") spam2(iconcat,__iconcat__, - "iconcat(a, b) -- Same as a += b, for a and b sequences.") + "a = iconcat(a, b) -- Same as a += b, for a and b sequences.") spam2(getitem,__getitem__, "getitem(a, b) -- Same as a[b].") spam2(setitem,__setitem__, @@ -219,7 +219,7 @@ spam2(setitem,__setitem__, spam2(delitem,__delitem__, "delitem(a, b) -- Same as del a[b].") spam2(pow,__pow__, "pow(a, b) -- Same as a ** b.") -spam2(ipow,__ipow__, "ipow(a, b) -- Same as a **= b.") +spam2(ipow,__ipow__, "a = ipow(a, b) -- Same as a **= b.") spam2(lt,__lt__, "lt(a, b) -- Same as aprop_doc); prop->prop_doc = get_doc; - } else { - /* Put __doc__ in dict of the subclass instance instead, - otherwise it gets shadowed by class's __doc__. */ - if (PyObject_SetAttrString(self, "__doc__", get_doc) != 0) - { - /* DECREF for props handled by _dealloc */ - Py_DECREF(get_doc); + } + else { + /* If this is a property subclass, put __doc__ + in dict of the subclass instance instead, + otherwise it gets shadowed by __doc__ in the + class's dict. */ + int err = PyObject_SetAttrString(self, "__doc__", get_doc); + Py_DECREF(get_doc); + if (err < 0) return -1; - } - Py_DECREF(get_doc); } prop->getter_doc = 1; - } else { + } + else if (PyErr_ExceptionMatches(PyExc_Exception)) { PyErr_Clear(); } + else { + return -1; + } } return 0; diff --git a/Objects/listobject.c b/Objects/listobject.c index 2bab4ef..09fba48 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -183,9 +183,12 @@ PyList_GetItem(PyObject *op, Py_ssize_t i) return NULL; } if (i < 0 || i >= Py_SIZE(op)) { - if (indexerr == NULL) + if (indexerr == NULL) { indexerr = PyUnicode_FromString( "list index out of range"); + if (indexerr == NULL) + return NULL; + } PyErr_SetObject(PyExc_IndexError, indexerr); return NULL; } @@ -406,9 +409,12 @@ static PyObject * list_item(PyListObject *a, Py_ssize_t i) { if (i < 0 || i >= Py_SIZE(a)) { - if (indexerr == NULL) + if (indexerr == NULL) { indexerr = PyUnicode_FromString( "list index out of range"); + if (indexerr == NULL) + return NULL; + } PyErr_SetObject(PyExc_IndexError, indexerr); return NULL; } diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 11dd43d..c1dd228 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -312,7 +312,10 @@ module_dealloc(PyModuleObject *m) if (m->md_def && m->md_def->m_free) m->md_def->m_free(m); if (m->md_dict != NULL) { - _PyModule_Clear((PyObject *)m); + /* If we are the only ones holding a reference, we can clear + the dictionary. */ + if (Py_REFCNT(m->md_dict) == 1) + _PyModule_Clear((PyObject *)m); Py_DECREF(m->md_dict); } if (m->md_state != NULL) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index e637cb3..f3ef1cb 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -197,20 +197,26 @@ get_normal_name(char *s) /* for utf-8 and latin-1 */ int i; for (i = 0; i < 12; i++) { int c = s[i]; - if (c == '\0') break; - else if (c == '_') buf[i] = '-'; - else buf[i] = tolower(c); + if (c == '\0') + break; + else if (c == '_') + buf[i] = '-'; + else + buf[i] = tolower(c); } buf[i] = '\0'; if (strcmp(buf, "utf-8") == 0 || - strncmp(buf, "utf-8-", 6) == 0) return "utf-8"; + strncmp(buf, "utf-8-", 6) == 0) + return "utf-8"; else if (strcmp(buf, "latin-1") == 0 || strcmp(buf, "iso-8859-1") == 0 || strcmp(buf, "iso-latin-1") == 0 || strncmp(buf, "latin-1-", 8) == 0 || strncmp(buf, "iso-8859-1-", 11) == 0 || - strncmp(buf, "iso-latin-1-", 12) == 0) return "iso-8859-1"; - else return s; + strncmp(buf, "iso-latin-1-", 12) == 0) + return "iso-8859-1"; + else + return s; } /* Return the coding spec in S, or NULL if none is found. */ @@ -336,12 +342,18 @@ check_bom(int get_char(struct tok_state *), /* Disable support for UTF-16 BOMs until a decision is made whether this needs to be supported. */ } else if (ch == 0xFE) { - ch = get_char(tok); if (ch != 0xFF) goto NON_BOM; - if (!set_readline(tok, "utf-16-be")) return 0; + ch = get_char(tok); + if (ch != 0xFF) + goto NON_BOM; + if (!set_readline(tok, "utf-16-be")) + return 0; tok->decoding_state = STATE_NORMAL; } else if (ch == 0xFF) { - ch = get_char(tok); if (ch != 0xFE) goto NON_BOM; - if (!set_readline(tok, "utf-16-le")) return 0; + ch = get_char(tok); + if (ch != 0xFE) + goto NON_BOM; + if (!set_readline(tok, "utf-16-le")) + return 0; tok->decoding_state = STATE_NORMAL; #endif } else { @@ -1036,7 +1048,7 @@ tok_backup(register struct tok_state *tok, register int c) { if (c != EOF) { if (--tok->cur < tok->buf) - Py_FatalError("tok_backup: begin of buffer"); + Py_FatalError("tok_backup: beginning of buffer"); if (*tok->cur != c) *tok->cur = c; } -- cgit v0.12