Commit 4aef703c authored by Georg Brandl's avatar Georg Brandl

Merged revisions...

Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

................
  r66801 | andrew.kuchling | 2008-10-04 23:51:59 +0200 (Sat, 04 Oct 2008) | 1 line

  Punctuation fix; expand dict.update docstring to be clearer
................
  r66803 | benjamin.peterson | 2008-10-05 00:15:31 +0200 (Sun, 05 Oct 2008) | 1 line

  fix typo
................
  r66804 | andrew.kuchling | 2008-10-05 02:11:56 +0200 (Sun, 05 Oct 2008) | 1 line

  #1415508 from Rocky Bernstein: add docstrings for enable_interspersed_args(), disable_interspersed_args()
................
  r66813 | andrew.kuchling | 2008-10-06 14:07:04 +0200 (Mon, 06 Oct 2008) | 3 lines

  Per Greg Ward, optparse is no longer being externally maintained.
  I'll look at the bugs in the Optik bug tracker and copy them to the Python bug
  tracker if they're still relevant.
................
  r66854 | georg.brandl | 2008-10-08 19:20:20 +0200 (Wed, 08 Oct 2008) | 2 lines

  #4059: patch up some sqlite docs.
................
  r66855 | georg.brandl | 2008-10-08 19:30:55 +0200 (Wed, 08 Oct 2008) | 2 lines

  #4058: fix some whatsnew markup.
................
  r66856 | georg.brandl | 2008-10-08 20:47:17 +0200 (Wed, 08 Oct 2008) | 3 lines

  #3935: properly support list subclasses in the C impl. of bisect.
  Patch reviewed by Raymond.
................
  r66866 | benjamin.peterson | 2008-10-09 22:54:43 +0200 (Thu, 09 Oct 2008) | 1 line

  update paragraph about __future__ for 2.6
................
  r66870 | armin.rigo | 2008-10-10 10:40:44 +0200 (Fri, 10 Oct 2008) | 2 lines

  Typo: "ThreadError" is the name in the C source.
................
  r66871 | benjamin.peterson | 2008-10-10 22:38:49 +0200 (Fri, 10 Oct 2008) | 1 line

  fix a small typo
................
  r66872 | benjamin.peterson | 2008-10-10 22:51:37 +0200 (Fri, 10 Oct 2008) | 1 line

  talk about how you can unzip with zip
................
  r66874 | benjamin.peterson | 2008-10-11 00:23:41 +0200 (Sat, 11 Oct 2008) | 1 line

  PyGILState_Acquire -> PyGILState_Ensure
................
  r66887 | benjamin.peterson | 2008-10-13 23:51:40 +0200 (Mon, 13 Oct 2008) | 1 line

  document how to disable fixers
................
  r66903 | benjamin.peterson | 2008-10-15 22:34:09 +0200 (Wed, 15 Oct 2008) | 1 line

  don't recurse into directories that start with '.'
................
  r66905 | benjamin.peterson | 2008-10-15 23:05:55 +0200 (Wed, 15 Oct 2008) | 1 line

  support the optional line argument for idle
................
  r66911 | benjamin.peterson | 2008-10-16 01:10:28 +0200 (Thu, 16 Oct 2008) | 41 lines

  Merged revisions 66805,66841,66860,66884-66886,66893,66907,66910 via svnmerge from
  svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3

  ........
    r66805 | benjamin.peterson | 2008-10-04 20:11:02 -0500 (Sat, 04 Oct 2008) | 1 line

    mention what the fixes directory is for
  ........
    r66841 | benjamin.peterson | 2008-10-07 17:48:12 -0500 (Tue, 07 Oct 2008) | 1 line

    use assertFalse and assertTrue
  ........
    r66860 | benjamin.peterson | 2008-10-08 16:05:07 -0500 (Wed, 08 Oct 2008) | 1 line

    instead of abusing the pattern matcher, use start_tree to find a next binding
  ........
    r66884 | benjamin.peterson | 2008-10-13 15:50:30 -0500 (Mon, 13 Oct 2008) | 1 line

    don't print tokens to stdout when -v is given
  ........
    r66885 | benjamin.peterson | 2008-10-13 16:28:57 -0500 (Mon, 13 Oct 2008) | 1 line

    add the -x option to disable fixers
  ........
    r66886 | benjamin.peterson | 2008-10-13 16:33:53 -0500 (Mon, 13 Oct 2008) | 1 line

    cut down on some crud
  ........
    r66893 | benjamin.peterson | 2008-10-14 17:16:54 -0500 (Tue, 14 Oct 2008) | 1 line

    add an optional set literal fixer
  ........
    r66907 | benjamin.peterson | 2008-10-15 16:59:41 -0500 (Wed, 15 Oct 2008) | 1 line

    don't write backup files by default
  ........
    r66910 | benjamin.peterson | 2008-10-15 17:43:10 -0500 (Wed, 15 Oct 2008) | 1 line

    add the -n option; it stops backupfiles from being written
  ........
................
  r66913 | benjamin.peterson | 2008-10-16 20:52:14 +0200 (Thu, 16 Oct 2008) | 1 line

  document that deque indexing is O(n) #4123
................
  r66927 | andrew.kuchling | 2008-10-16 22:15:47 +0200 (Thu, 16 Oct 2008) | 1 line

  Fix wording (2.6.1 backport candidate)
................
  r66932 | benjamin.peterson | 2008-10-16 23:09:28 +0200 (Thu, 16 Oct 2008) | 1 line

  check for error conditions in _json #3623
................
  r66938 | benjamin.peterson | 2008-10-16 23:27:54 +0200 (Thu, 16 Oct 2008) | 1 line

  fix possible ref leak
................
  r66942 | benjamin.peterson | 2008-10-16 23:48:06 +0200 (Thu, 16 Oct 2008) | 1 line

  fix more possible ref leaks in _json and use Py_CLEAR
................
  r66962 | benjamin.peterson | 2008-10-17 22:01:01 +0200 (Fri, 17 Oct 2008) | 1 line

  clarify CALL_FUNCTION #4141
................
  r66964 | georg.brandl | 2008-10-17 23:41:49 +0200 (Fri, 17 Oct 2008) | 2 lines

  Fix duplicate word.
................
  r66973 | armin.ronacher | 2008-10-19 10:27:43 +0200 (Sun, 19 Oct 2008) | 3 lines

  Fixed #4067 by implementing _attributes and _fields for the AST root node.
................
  r66974 | benjamin.peterson | 2008-10-19 15:59:01 +0200 (Sun, 19 Oct 2008) | 1 line

  fix compiler warning
................
  r66977 | benjamin.peterson | 2008-10-19 21:39:16 +0200 (Sun, 19 Oct 2008) | 1 line

  mention -n
................
  r66992 | benjamin.peterson | 2008-10-21 22:51:13 +0200 (Tue, 21 Oct 2008) | 1 line

  make sure to call iteritems()
................
  r66998 | benjamin.peterson | 2008-10-22 22:57:43 +0200 (Wed, 22 Oct 2008) | 1 line

  fix a few typos
................
  r66999 | benjamin.peterson | 2008-10-22 23:05:30 +0200 (Wed, 22 Oct 2008) | 1 line

  and another typo...
................
  r67002 | hirokazu.yamamoto | 2008-10-23 02:37:33 +0200 (Thu, 23 Oct 2008) | 1 line

  Issue #4183: Some tests didn't run with pickle.HIGHEST_PROTOCOL.
................
  r67005 | walter.doerwald | 2008-10-23 15:11:39 +0200 (Thu, 23 Oct 2008) | 2 lines

  Use the correct names of the stateless codec functions (Fixes issue 4178).
................
  r67007 | benjamin.peterson | 2008-10-23 23:43:48 +0200 (Thu, 23 Oct 2008) | 1 line

  only nonempty __slots__ don't work
................
  r67028 | benjamin.peterson | 2008-10-26 01:27:07 +0200 (Sun, 26 Oct 2008) | 1 line

  don't use a catch-all
................
  r67040 | armin.rigo | 2008-10-28 18:01:21 +0100 (Tue, 28 Oct 2008) | 5 lines

  Fix one of the tests: it relied on being present in an "output test" in
  order to actually test what it was supposed to test, i.e. that the code
  in the __del__ method did not crash.  Use instead the new helper
  test_support.captured_output().
................
  r67041 | benjamin.peterson | 2008-10-29 21:33:00 +0100 (Wed, 29 Oct 2008) | 1 line

  mention the version gettempdir() was added
................
  r67044 | amaury.forgeotdarc | 2008-10-30 00:15:57 +0100 (Thu, 30 Oct 2008) | 3 lines

  Correct error message in io.open():
  closefd=True is the only accepted value with a file name.
................
  r67070 | benjamin.peterson | 2008-10-31 21:41:44 +0100 (Fri, 31 Oct 2008) | 1 line

  rephrase has_key doc
................
  r67089 | benjamin.peterson | 2008-11-03 21:43:20 +0100 (Mon, 03 Nov 2008) | 1 line

  clarify by splitting into multiple paragraphs
................
  r67091 | benjamin.peterson | 2008-11-03 23:34:57 +0100 (Mon, 03 Nov 2008) | 1 line

  move a FileIO test to test_fileio
................
  r67101 | georg.brandl | 2008-11-04 21:49:35 +0100 (Tue, 04 Nov 2008) | 2 lines

  #4167: fix markup glitches.
................
  r67117 | georg.brandl | 2008-11-06 11:17:58 +0100 (Thu, 06 Nov 2008) | 2 lines

  #4268: Use correct module for two toplevel functions.
................
  r67118 | georg.brandl | 2008-11-06 11:19:11 +0100 (Thu, 06 Nov 2008) | 2 lines

  #4267: small fixes in sqlite3 docs.
................
  r67119 | georg.brandl | 2008-11-06 11:20:49 +0100 (Thu, 06 Nov 2008) | 2 lines

  #4245: move Thread section to the top.
................
  r67123 | georg.brandl | 2008-11-06 19:49:15 +0100 (Thu, 06 Nov 2008) | 2 lines

  #4247: add "pass" examples to tutorial.
................
  r67124 | andrew.kuchling | 2008-11-06 20:23:02 +0100 (Thu, 06 Nov 2008) | 1 line

  Fix grammar error; reword two paragraphs
................
parent 939582fd
......@@ -16,6 +16,7 @@ docs@python.org), and we'll be glad to correct the problem.
* A. Amoroso
* Pehr Anderson
* Oliver Andrich
* Heidi Annexstad
* Jesús Cea Avión
* Daniel Barclay
* Chris Barker
......@@ -189,6 +190,7 @@ docs@python.org), and we'll be glad to correct the problem.
* Reuben Sumner
* Kalle Svensson
* Jim Tittsler
* David Turner
* Ville Vainio
* Martijn Vries
* Charles G. Waldman
......
......@@ -755,11 +755,11 @@ created.
:cmacro:`Py_END_ALLOW_THREADS` macros is acceptable.
The return value is an opaque "handle" to the thread state when
:cfunc:`PyGILState_Acquire` was called, and must be passed to
:cfunc:`PyGILState_Ensure` was called, and must be passed to
:cfunc:`PyGILState_Release` to ensure Python is left in the same state. Even
though recursive calls are allowed, these handles *cannot* be shared - each
unique call to :cfunc:`PyGILState_Ensure` must save the handle for its call to
:cfunc:`PyGILState_Release`.
unique call to :cfunc:`PyGILState_Ensure` must save the handle for its call
to :cfunc:`PyGILState_Release`.
When the function returns, the current thread will hold the GIL. Failure is a
fatal error.
......
......@@ -37,8 +37,8 @@ It can be converted to Python 3.x code via 2to3 on the command line::
A diff against the original source file is printed. 2to3 can also write the
needed modifications right back to the source file. (Of course, a backup of the
original is also be made.) Writing the changes back is enabled with the
:option:`-w` flag::
original is also be made unless :option:`-n` is also given.) Writing the
changes back is enabled with the :option:`-w` flag::
$ 2to3 -w example.py
......@@ -50,16 +50,19 @@ After transformation, :file:`example.py` looks like this::
name = input()
greet(name)
Comments and and exact indentation are preserved throughout the translation
process.
Comments and exact indentation are preserved throughout the translation process.
By default, 2to3 runs a set of predefined fixers. The :option:`-l` flag lists
all available fixers. An explicit set of fixers to run can be given by use of
the :option:`-f` flag. The following example runs only the ``imports`` and
``has_key`` fixers::
all available fixers. An explicit set of fixers to run can be given with
:option:`-f`. Likewise the :option:`-x` explicitly disables a fixer. The
following example runs only the ``imports`` and ``has_key`` fixers::
$ 2to3 -f imports -f has_key example.py
This command runs every fixer except the ``apply`` fixer::
$ 2to3 -x apply example.py
Some fixers are *explicit*, meaning they aren't run by default and must be
listed on the command line to be run. Here, in addition to the default fixers,
the ``idioms`` fixer is run::
......@@ -68,25 +71,25 @@ the ``idioms`` fixer is run::
Notice how passing ``all`` enables all default fixers.
Sometimes 2to3 will find a place in your source code that needs to be
changed, but 2to3 cannot fix automatically. In this case, 2to3 will print a
warning beneath the diff for a file. You should address the warning in order to
have compliant 3.x code.
Sometimes 2to3 will find a place in your source code that needs to be changed,
but 2to3 cannot fix automatically. In this case, 2to3 will print a warning
beneath the diff for a file. You should address the warning in order to have
compliant 3.x code.
2to3 can also refactor doctests. To enable this mode, use the :option:`-d`
flag. Note that *only* doctests will be refactored. This also doesn't require
the module to be valid Python. For example, doctest like examples in a reST
document could also be refactored with this option.
The :option:`-v` option enables the output of more information on the
translation process.
The :option:`-v` option enables output of more information on the translation
process.
When the :option:`-p` is passed, 2to3 treats ``print`` as a function instead
of a statement. This is useful when ``from __future__ import print_function``
is being used. If this option is not given, the print fixer will surround
print calls in an extra set of parentheses because it cannot differentiate
between the print statement with parentheses (such as ``print ("a" + "b" +
"c")``) and a true function call.
When the :option:`-p` is passed, 2to3 treats ``print`` as a function instead of
a statement. This is useful when ``from __future__ import print_function`` is
being used. If this option is not given, the print fixer will surround print
calls in an extra set of parentheses because it cannot differentiate between the
print statement with parentheses (such as ``print ("a" + "b" + "c")``) and a
true function call.
:mod:`lib2to3` - 2to3's library
......
......@@ -32,9 +32,9 @@ It defines the following functions:
* ``name`` The name of the encoding;
* ``encoder`` The stateless encoding function;
* ``encode`` The stateless encoding function;
* ``decoder`` The stateless decoding function;
* ``decode`` The stateless decoding function;
* ``incrementalencoder`` An incremental encoder class or factory function;
......@@ -46,7 +46,7 @@ It defines the following functions:
The various functions or classes take the following arguments:
*encoder* and *decoder*: These must be functions or methods which have the same
*encode* and *decode*: These must be functions or methods which have the same
interface as the :meth:`encode`/:meth:`decode` methods of Codec instances (see
Codec Interface). The functions/methods are expected to work in a stateless
mode.
......
......@@ -247,7 +247,9 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
In addition to the above, deques support iteration, pickling, ``len(d)``,
``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with
the :keyword:`in` operator, and subscript references such as ``d[-1]``.
the :keyword:`in` operator, and subscript references such as ``d[-1]``. Indexed
access is O(1) at both ends but slows to O(n) in the middle. For fast random
access, use lists instead.
Example:
......
......@@ -755,7 +755,8 @@ the more significant byte last.
opcode finds the keyword parameters first. For each keyword argument, the value
is on top of the key. Below the keyword parameters, the positional parameters
are on the stack, with the right-most parameter on top. Below the parameters,
the function object to call is on the stack.
the function object to call is on the stack. Pops all function arguments, and
the function itself off the stack, and pushes the return value.
.. opcode:: MAKE_FUNCTION (argc)
......
......@@ -159,6 +159,7 @@ Since creating a message object structure from a string or a file object is such
a common task, two functions are provided as a convenience. They are available
in the top-level :mod:`email` package namespace.
.. currentmodule:: email
.. function:: message_from_string(s[, _class[, strict]])
......
......@@ -315,7 +315,7 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
.. method:: FTP.quit()
Send a ``QUIT`` command to the server and close the connection. This is the
"polite" way to close a connection, but it may raise an exception of the server
"polite" way to close a connection, but it may raise an exception if the server
responds with an error to the ``QUIT`` command. This implies a call to the
:meth:`close` method which renders the :class:`FTP` instance useless for
subsequent calls (see below).
......
......@@ -1397,6 +1397,18 @@ available. They are listed here in alphabetical order.
makes possible an idiom for clustering a data series into n-length groups
using ``zip(*[iter(s)]*n)``.
:func:`zip` in conjunction with the ``*`` operator can be used to unzip a
list::
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> zipped
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zipped)
>>> x == x2, y == y2
True
.. versionadded:: 2.0
.. versionchanged:: 2.4
......
......@@ -95,7 +95,7 @@ The module also offers three general purpose functions based on heaps.
Merge multiple sorted inputs into a single sorted output (for example, merge
timestamped entries from multiple log files). Returns an :term:`iterator`
over over the sorted values.
over the sorted values.
Similar to ``sorted(itertools.chain(*iterables))`` but returns an iterable, does
not pull the data into memory all at once, and assumes that each of the input
......
......@@ -363,7 +363,7 @@ http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
Filter specific flags
*:const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags*
:const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags
+----------------------------+--------------------------------------------+
| Constant | Meaning |
......@@ -372,7 +372,7 @@ http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
+----------------------------+--------------------------------------------+
*:const:`KQ_FILTER_VNODE` filter flags*
:const:`KQ_FILTER_VNODE` filter flags
+----------------------------+--------------------------------------------+
| Constant | Meaning |
......@@ -393,7 +393,7 @@ http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
+----------------------------+--------------------------------------------+
*:const:`KQ_FILTER_PROC` filter flags*
:const:`KQ_FILTER_PROC` filter flags
+----------------------------+--------------------------------------------+
| Constant | Meaning |
......@@ -416,7 +416,7 @@ http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
| :const:`KQ_NOTE_TRACKERR` | unable to attach to a child |
+----------------------------+--------------------------------------------+
*:const:`KQ_FILTER_NETDEV` filter flags* [not available on Mac OS X]
:const:`KQ_FILTER_NETDEV` filter flags [not available on Mac OS X]
+----------------------------+--------------------------------------------+
| Constant | Meaning |
......
......@@ -276,11 +276,15 @@ The module :mod:`socket` exports the following constants and functions:
.. function:: gethostname()
Return a string containing the hostname of the machine where the Python
interpreter is currently executing. If you want to know the current machine's IP
address, you may want to use ``gethostbyname(gethostname())``. This operation
assumes that there is a valid address-to-host mapping for the host, and the
assumption does not always hold. Note: :func:`gethostname` doesn't always return
the fully qualified domain name; use ``getfqdn()`` (see above).
interpreter is currently executing.
If you want to know the current machine's IP address, you may want to use
``gethostbyname(gethostname())``. This operation assumes that there is a
valid address-to-host mapping for the host, and the assumption does not
always hold.
Note: :func:`gethostname` doesn't always return the fully qualified domain
name; use ``getfqdn()`` (see above).
.. function:: gethostbyaddr(ip_address)
......
This diff is collapsed.
......@@ -1924,7 +1924,8 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
.. method:: has_key(key)
``dict.has_key(key)`` is equivalent to ``key in d``, but deprecated.
Test for the presence of *key* in the dictionary. :meth:`has_key` is
deprecated in favor of ``key in d``.
.. method:: items()
......
......@@ -318,8 +318,8 @@ Replacing /bin/sh shell backquote
output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]
Replacing shell pipe line
^^^^^^^^^^^^^^^^^^^^^^^^^
Replacing shell pipeline
^^^^^^^^^^^^^^^^^^^^^^^^
::
......
......@@ -224,6 +224,8 @@ the appropriate function arguments, instead.
:data:`tempdir` is not ``None``, this simply returns its contents; otherwise,
the search described above is performed, and the result returned.
.. versionadded:: 2.3
.. data:: template
......
......@@ -99,7 +99,7 @@ It defines the following constant and functions:
*size* argument specifies the stack size to be used for subsequently created
threads, and must be 0 (use platform or configured default) or a positive
integer value of at least 32,768 (32kB). If changing the thread stack size is
unsupported, a :exc:`ThreadError` is raised. If the specified stack size is
unsupported, the :exc:`error` exception is raised. If the specified stack size is
invalid, a :exc:`ValueError` is raised and the stack size is unmodified. 32kB
is currently the minimum supported stack size value to guarantee sufficient
stack space for the interpreter itself. Note that some platforms may have
......
This diff is collapsed.
......@@ -1663,8 +1663,8 @@ Notes on using *__slots__*
defined. As a result, subclasses will have a *__dict__* unless they also define
*__slots__*.
* *__slots__* do not work for classes derived from "variable-length" built-in
types such as :class:`long`, :class:`str` and :class:`tuple`.
* Nonempty *__slots__* does not work for classes derived from "variable-length"
built-in types such as :class:`long`, :class:`str` and :class:`tuple`.
* Any non-string iterable may be assigned to *__slots__*. Mappings may also be
used; however, in the future, special meaning may be assigned to the values
......
......@@ -788,10 +788,11 @@ can appear before a future statement are:
* blank lines, and
* other future statements.
The features recognized by Python 2.5 are ``absolute_import``, ``division``,
``generators``, ``nested_scopes`` and ``with_statement``. ``generators`` and
``nested_scopes`` are redundant in Python version 2.3 and above because they
are always enabled.
The features recognized by Python 2.6 are ``unicode_literals``,
``print_function``, ``absolute_import``, ``division``, ``generators``,
``nested_scopes`` and ``with_statement``. ``generators``, ``with_statement``,
``nested_scopes`` are redundant in Python version 2.6 and above because they are
always enabled.
A future statement is recognized and treated specially at compile time: Changes
to the semantics of core constructs are often implemented by generating
......
......@@ -166,6 +166,41 @@ required syntactically but the program requires no action. For example::
... pass # Busy-wait for keyboard interrupt (Ctrl+C)
...
This is commonly used for creating minimal classes such as exceptions, or
for ignoring unwanted exceptions::
>>> class ParserError(Exception):
... pass
...
>>> try:
... import audioop
... except ImportError:
... pass
...
Another place :keyword:`pass` can be used is as a place-holder for a function or
conditional body when you are working on new code, allowing you to keep
thinking at a more abstract level. However, as :keyword:`pass` is silently
ignored, a better choice may be to raise a :exc:`NotImplementedError`
exception::
>>> def initlog(*args):
... raise NotImplementedError # Open logfile if not already open
... if not logfp:
... raise NotImplementedError # Set up dummy log back-end
... raise NotImplementedError('Call log initialization handler')
...
If :keyword:`pass` were used here and you later ran tests, they may fail
without indicating why. Using :exc:`NotImplementedError` causes this code
to raise an exception, telling you exactly where the incomplete code
is. Note the two calling styles of the exceptions above.
The first style, with no message but with an accompanying comment,
lets you easily leave the comment when you remove the exception,
which ideally would be a good description for
the block of code the exception is a placeholder for. However, the
third example, providing a message for the exception, will produce
a more useful traceback.
.. _tut-functions:
......
This diff is collapsed.
......@@ -2,6 +2,7 @@ import sys
import decimal
from unittest import TestCase
import json
import json.decoder
class TestScanString(TestCase):
......@@ -100,3 +101,9 @@ class TestScanString(TestCase):
self.assertEquals(
scanstring('["Bad value", truth]', 2, None, True),
(u'Bad value', 12))
def test_issue3623(self):
self.assertRaises(ValueError, json.decoder.scanstring, b"xxx", 1,
"xxx")
self.assertRaises(UnicodeDecodeError,
json.encoder.encode_basestring_ascii, b"xx\xff")
......@@ -28,14 +28,18 @@ class FixNext(fixer_base.BaseFix):
any* > >
|
global=global_stmt< 'global' any* 'next' any* >
|
mod=file_input< any+ >
"""
order = "pre" # Pre-order tree traversal
def start_tree(self, tree, filename):
super(FixNext, self).start_tree(tree, filename)
n = find_binding('next', tree)
if n:
self.warning(n, bind_warning)
self.shadowed_next = True
else:
self.shadowed_next = False
def transform(self, node, results):
......@@ -69,11 +73,6 @@ class FixNext(fixer_base.BaseFix):
elif "global" in results:
self.warning(node, bind_warning)
self.shadowed_next = True
elif mod:
n = find_binding('next', mod)
if n:
self.warning(n, bind_warning)
self.shadowed_next = True
### The following functions help test if node is part of an assignment
......
"""
Optional fixer to transform set() calls to set literals.
"""
# Author: Benjamin Peterson
from lib2to3 import fixer_base, pytree
from lib2to3.fixer_util import token, syms
class FixSetLiteral(fixer_base.BaseFix):
explicit = True
PATTERN = """power< 'set' trailer< '('
(atom=atom< '[' (items=listmaker< any ((',' any)* [',']) >
|
single=any) ']' >
|
atom< '(' items=testlist_gexp< any ((',' any)* [',']) > ')' >
)
')' > >
"""
def transform(self, node, results):
single = results.get("single")
if single:
# Make a fake listmaker
fake = pytree.Node(syms.listmaker, [single.clone()])
single.replace(fake)
items = fake
else:
items = results["items"]
# Build the contents of the literal
literal = [pytree.Leaf(token.LBRACE, "{")]
literal.extend(n.clone() for n in items.children)
literal.append(pytree.Leaf(token.RBRACE, "}"))
# Set the prefix of the right brace to that of the ')' or ']'
literal[-1].set_prefix(items.get_next_sibling().get_prefix())
maker = pytree.Node(syms.dictsetmaker, literal)
maker.set_prefix(node.get_prefix())
# If the original was a one tuple, we need to remove the extra comma.
if len(maker.children) == 4:
n = maker.children[2]
n.remove()
maker.children[-1].set_prefix(n.get_prefix())
# Finally, replace the set call with our shiny new literal.
return maker
......@@ -15,10 +15,31 @@ class StdoutRefactoringTool(refactor.RefactoringTool):
Prints output to stdout.
"""
def __init__(self, fixers, options, explicit, nobackups):
self.nobackups = nobackups
super(StdoutRefactoringTool, self).__init__(fixers, options, explicit)
def log_error(self, msg, *args, **kwargs):
self.errors.append((msg, args, kwargs))
self.logger.error(msg, *args, **kwargs)
def write_file(self, new_text, filename, old_text):
if not self.nobackups:
# Make backup
backup = filename + ".bak"
if os.path.lexists(backup):
try:
os.remove(backup)
except os.error, err:
self.log_message("Can't remove backup %s", backup)
try:
os.rename(filename, backup)
except os.error, err:
self.log_message("Can't rename %s to %s", filename, backup)
# Actually write the new file
super(StdoutRefactoringTool, self).write_file(new_text,
filename, old_text)
def print_output(self, lines):
for line in lines:
print line
......@@ -39,7 +60,9 @@ def main(fixer_pkg, args=None):
parser.add_option("-d", "--doctests_only", action="store_true",
help="Fix up doctests only")
parser.add_option("-f", "--fix", action="append", default=[],
help="Each FIX specifies a transformation; default all")
help="Each FIX specifies a transformation; default: all")
parser.add_option("-x", "--nofix", action="append", default=[],
help="Prevent a fixer from being run.")
parser.add_option("-l", "--list-fixes", action="store_true",
help="List available transformations (fixes/fix_*.py)")
parser.add_option("-p", "--print-function", action="store_true",
......@@ -48,10 +71,14 @@ def main(fixer_pkg, args=None):
help="More verbose logging")
parser.add_option("-w", "--write", action="store_true",
help="Write back modified files")
parser.add_option("-n", "--nobackups", action="store_true", default=False,
help="Don't write backups for modified files.")
# Parse command line arguments
refactor_stdin = False
options, args = parser.parse_args(args)
if not options.write and options.nobackups:
parser.error("Can't use -n without -w")
if options.list_fixes:
print "Available transformations for the -f/--fix option:"
for fixname in refactor.get_all_fix_names(fixer_pkg):
......@@ -74,15 +101,22 @@ def main(fixer_pkg, args=None):
# Initialize the refactoring tool
rt_opts = {"print_function" : options.print_function}
avail_names = refactor.get_fixers_from_package(fixer_pkg)
explicit = []
avail_fixes = set(refactor.get_fixers_from_package(fixer_pkg))
unwanted_fixes = set(fixer_pkg + ".fix_" + fix for fix in options.nofix)
explicit = set()
if options.fix:
explicit = [fixer_pkg + ".fix_" + fix
for fix in options.fix if fix != "all"]
fixer_names = avail_names if "all" in options.fix else explicit
all_present = False
for fix in options.fix:
if fix == "all":
all_present = True
else:
explicit.add(fixer_pkg + ".fix_" + fix)
requested = avail_fixes.union(explicit) if all_present else explicit
else:
fixer_names = avail_names
rt = StdoutRefactoringTool(fixer_names, rt_opts, explicit=explicit)
requested = avail_fixes.union(explicit)
fixer_names = requested.difference(unwanted_fixes)
rt = StdoutRefactoringTool(sorted(fixer_names), rt_opts, sorted(explicit),
options.nobackups)
# Refactor all files and directories passed as arguments
if not rt.errors:
......
......@@ -36,9 +36,7 @@ def get_all_fix_names(fixer_pkg, remove_prefix=True):
pkg = __import__(fixer_pkg, [], [], ["*"])
fixer_dir = os.path.dirname(pkg.__file__)
fix_names = []
names = os.listdir(fixer_dir)
names.sort()
for name in names:
for name in sorted(os.listdir(fixer_dir)):
if name.startswith("fix_") and name.endswith(".py"):
if remove_prefix:
name = name[4:]
......@@ -253,7 +251,7 @@ class RefactoringTool(object):
there were errors during the parse.
"""
try:
tree = self.driver.parse_string(data,1)
tree = self.driver.parse_string(data)
except Exception, err:
self.log_error("Can't parse %s: %s: %s",
name, err.__class__.__name__, err)
......@@ -352,23 +350,13 @@ class RefactoringTool(object):
else:
self.log_debug("Not writing changes to %s", filename)
def write_file(self, new_text, filename, old_text=None):
def write_file(self, new_text, filename, old_text):
"""Writes a string to a file.
It first shows a unified diff between the old text and the new text, and
then rewrites the file; the latter is only done if the write option is
set.
"""
backup = filename + ".bak"
if os.path.lexists(backup):
try:
os.remove(backup)
except os.error, err:
self.log_message("Can't remove backup %s", backup)
try:
os.rename(filename, backup)
except os.error, err:
self.log_message("Can't rename %s to %s", filename, backup)
try:
f = open(filename, "w")
except os.error, err:
......
Files in this directory:
In this directory:
- py2_test_grammar.py -- test file that exercises most/all of Python 2.x's grammar.
- py3_test_grammar.py -- test file that exercises most/all of Python 3.x's grammar.
- infinite_recursion.py -- test file that causes lib2to3's faster recursive pattern matching
scheme to fail, but passes when lib2to3 falls back to iterative pattern matching.
- fixes/ -- for use by test_refactor.py
......@@ -3385,6 +3385,134 @@ class Test_import(FixerTestCase):
"""
self.check_both(b, a)
class Test_set_literal(FixerTestCase):
fixer = "set_literal"
def test_basic(self):
b = """set([1, 2, 3])"""
a = """{1, 2, 3}"""
self.check(b, a)
b = """set((1, 2, 3))"""
a = """{1, 2, 3}"""
self.check(b, a)
b = """set((1,))"""
a = """{1}"""
self.check(b, a)
b = """set([1])"""
self.check(b, a)
b = """set((a, b))"""
a = """{a, b}"""
self.check(b, a)
b = """set([a, b])"""
self.check(b, a)
b = """set((a*234, f(args=23)))"""
a = """{a*234, f(args=23)}"""
self.check(b, a)
b = """set([a*23, f(23)])"""
a = """{a*23, f(23)}"""
self.check(b, a)
b = """set([a-234**23])"""
a = """{a-234**23}"""
self.check(b, a)
def test_listcomps(self):
b = """set([x for x in y])"""
a = """{x for x in y}"""
self.check(b, a)
b = """set([x for x in y if x == m])"""
a = """{x for x in y if x == m}"""
self.check(b, a)
b = """set([x for x in y for a in b])"""
a = """{x for x in y for a in b}"""
self.check(b, a)
b = """set([f(x) - 23 for x in y])"""
a = """{f(x) - 23 for x in y}"""
self.check(b, a)
def test_whitespace(self):
b = """set( [1, 2])"""
a = """{1, 2}"""
self.check(b, a)
b = """set([1 , 2])"""
a = """{1 , 2}"""
self.check(b, a)
b = """set([ 1 ])"""
a = """{ 1 }"""
self.check(b, a)
b = """set( [1] )"""
a = """{1}"""
self.check(b, a)
b = """set([ 1, 2 ])"""
a = """{ 1, 2 }"""
self.check(b, a)
b = """set([x for x in y ])"""
a = """{x for x in y }"""
self.check(b, a)
b = """set(
[1, 2]
)
"""
a = """{1, 2}\n"""
self.check(b, a)
def test_comments(self):
b = """set((1, 2)) # Hi"""
a = """{1, 2} # Hi"""
self.check(b, a)
# This isn't optimal behavior, but the fixer is optional.
b = """
# Foo
set( # Bar
(1, 2)
)
"""
a = """
# Foo
{1, 2}
"""
self.check(b, a)
def test_unchanged(self):
s = """set()"""
self.unchanged(s)
s = """set(a)"""
self.unchanged(s)
s = """set(a, b, c)"""
self.unchanged(s)
# Don't transform generators because they might have to be lazy.
s = """set(x for x in y)"""
self.unchanged(s)
s = """set(x for x in y if z)"""
self.unchanged(s)
s = """set(a*823-23**2 + f(23))"""
self.unchanged(s)
class Test_sys_exc(FixerTestCase):
fixer = "sys_exc"
......
......@@ -353,29 +353,29 @@ class TestPatterns(support.TestCase):
# Build a pattern matching a leaf
pl = pytree.LeafPattern(100, "foo", name="pl")
r = {}
self.assertEqual(pl.match(root, results=r), False)
self.assertFalse(pl.match(root, results=r))
self.assertEqual(r, {})
self.assertEqual(pl.match(n1, results=r), False)
self.assertFalse(pl.match(n1, results=r))
self.assertEqual(r, {})
self.assertEqual(pl.match(n2, results=r), False)
self.assertFalse(pl.match(n2, results=r))
self.assertEqual(r, {})
self.assertEqual(pl.match(l1, results=r), True)
self.assertTrue(pl.match(l1, results=r))
self.assertEqual(r, {"pl": l1})
r = {}
self.assertEqual(pl.match(l2, results=r), False)
self.assertFalse(pl.match(l2, results=r))
self.assertEqual(r, {})
# Build a pattern matching a node
pn = pytree.NodePattern(1000, [pl], name="pn")
self.assertEqual(pn.match(root, results=r), False)
self.assertFalse(pn.match(root, results=r))
self.assertEqual(r, {})
self.assertEqual(pn.match(n1, results=r), False)
self.assertFalse(pn.match(n1, results=r))
self.assertEqual(r, {})
self.assertEqual(pn.match(n2, results=r), True)
self.assertTrue(pn.match(n2, results=r))
self.assertEqual(r, {"pn": n2, "pl": l3})
r = {}
self.assertEqual(pn.match(l1, results=r), False)
self.assertFalse(pn.match(l1, results=r))
self.assertEqual(r, {})
self.assertEqual(pn.match(l2, results=r), False)
self.assertFalse(pn.match(l2, results=r))
self.assertEqual(r, {})
def testWildcardPatterns(self):
......@@ -391,11 +391,11 @@ class TestPatterns(support.TestCase):
pn = pytree.NodePattern(1000, [pl], name="pn")
pw = pytree.WildcardPattern([[pn], [pl, pl]], name="pw")
r = {}
self.assertEqual(pw.match_seq([root], r), False)
self.assertFalse(pw.match_seq([root], r))
self.assertEqual(r, {})
self.assertEqual(pw.match_seq([n1], r), False)
self.assertFalse(pw.match_seq([n1], r))
self.assertEqual(r, {})
self.assertEqual(pw.match_seq([n2], r), True)
self.assertTrue(pw.match_seq([n2], r))
# These are easier to debug
self.assertEqual(sorted(r.keys()), ["pl", "pn", "pw"])
self.assertEqual(r["pl"], l1)
......@@ -404,7 +404,7 @@ class TestPatterns(support.TestCase):
# But this is equivalent
self.assertEqual(r, {"pl": l1, "pn": n2, "pw": [n2]})
r = {}
self.assertEqual(pw.match_seq([l1, l3], r), True)
self.assertTrue(pw.match_seq([l1, l3], r))
self.assertEqual(r, {"pl": l3, "pw": [l1, l3]})
self.assert_(r["pl"] is l3)
r = {}
......
......@@ -123,7 +123,6 @@ class TestRefactoringTool(unittest.TestCase):
def test_refactor_file(self):
test_file = os.path.join(FIXER_DIR, "parrot_example.py")
backup = test_file + ".bak"
old_contents = open(test_file, "r").read()
rt = self.rt()
......@@ -133,14 +132,8 @@ class TestRefactoringTool(unittest.TestCase):
rt.refactor_file(test_file, True)
try:
self.assertNotEqual(old_contents, open(test_file, "r").read())
self.assertTrue(os.path.exists(backup))
self.assertEqual(old_contents, open(backup, "r").read())
finally:
open(test_file, "w").write(old_contents)
try:
os.unlink(backup)
except OSError:
pass
def test_refactor_docstring(self):
rt = self.rt()
......
"""optparse - a powerful, extensible, and easy-to-use option parser.
"""A powerful, extensible, and easy-to-use option parser.
By Greg Ward <gward@python.net>
Originally distributed as Optik; see http://optik.sourceforge.net/ .
If you have problems with this module, please do not file bugs,
patches, or feature requests with Python; instead, use Optik's
SourceForge project page:
http://sourceforge.net/projects/optik
Originally distributed as Optik.
For support, use the optik-users@lists.sourceforge.net mailing list
(http://lists.sourceforge.net/lists/listinfo/optik-users).
"""
# Python developers: please do not make changes to this file, since
# it is automatically generated from the Optik source code.
__version__ = "1.5.3"
__all__ = ['Option',
......@@ -1274,9 +1266,19 @@ class OptionParser (OptionContainer):
self.usage = usage
def enable_interspersed_args(self):
"""Set parsing to not stop on the first non-option, allowing
interspersing switches with command arguments. This is the
default behavior. See also disable_interspersed_args() and the
class documentation description of the attribute
allow_interspersed_args."""
self.allow_interspersed_args = True
def disable_interspersed_args(self):
"""Set parsing to stop on the first non-option. Use this if
you have a command processor which runs another command that
has options of its own and you want to make sure these options
don't get confused.
"""
self.allow_interspersed_args = False
def set_process_default_values(self, process):
......
......@@ -196,6 +196,17 @@ class TestInsort(unittest.TestCase):
def test_backcompatibility(self):
self.assertEqual(self.module.insort, self.module.insort_right)
def test_listDerived(self):
class List(list):
data = []
def insert(self, index, item):
self.data.insert(index, item)
lst = List()
self.module.insort_left(lst, 10)
self.module.insort_right(lst, 5)
self.assertEqual([5, 10], lst.data)
class TestInsortPython(TestInsort):
module = py_bisect
......
......@@ -397,7 +397,7 @@ class BaseBytesTest(unittest.TestCase):
self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b''))
def test_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0":
b = self.type2test(b)
ps = pickle.dumps(b, proto)
......@@ -947,7 +947,7 @@ class ByteArraySubclassTest(unittest.TestCase):
a = ByteArraySubclass(b"abcd")
a.x = 10
a.y = ByteArraySubclass(b"efgh")
for proto in range(pickle.HIGHEST_PROTOCOL):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
b = pickle.loads(pickle.dumps(a, proto))
self.assertNotEqual(id(a), id(b))
self.assertEqual(a, b)
......
......@@ -1136,14 +1136,10 @@ order (MRO) for bases """
def __del__(self_):
self.assertEqual(self_.a, 1)
self.assertEqual(self_.b, 2)
save_stderr = sys.stderr
sys.stderr = sys.stdout
with test_support.captured_output('stderr') as s:
h = H()
try:
del h
finally:
sys.stderr = save_stderr
self.assertEqual(s.getvalue(), '')
def test_slots_special(self):
# Testing __dict__ and __weakref__ in __slots__...
......
......@@ -7,7 +7,7 @@ import unittest
from array import array
from weakref import proxy
from test.test_support import TESTFN, findfile, run_unittest
from test.test_support import TESTFN, findfile, check_warnings, run_unittest
from UserList import UserList
import _fileio
......@@ -241,6 +241,14 @@ class OtherFileTests(unittest.TestCase):
def testInvalidInit(self):
self.assertRaises(TypeError, _fileio._FileIO, "1", 0, 0)
def testWarnings(self):
with check_warnings() as w:
self.assertEqual(w.warnings, [])
self.assertRaises(TypeError, _fileio._FileIO, [])
self.assertEqual(w.warnings, [])
self.assertRaises(ValueError, _fileio._FileIO, "/some/invalid/name", "rt")
self.assertEqual(w.warnings, [])
def test_main():
# Historically, these tests have been sloppy about removing TESTFN.
......
......@@ -1236,13 +1236,6 @@ class MiscIOTest(unittest.TestCase):
else:
self.assert_(issubclass(obj, io.IOBase))
def test_fileio_warnings(self):
with test_support.check_warnings() as w:
self.assertEqual(w.warnings, [])
self.assertRaises(TypeError, io.FileIO, [])
self.assertEqual(w.warnings, [])
self.assertRaises(ValueError, io.FileIO, "/some/invalid/name", "rt")
self.assertEqual(w.warnings, [])
def test_main():
test_support.run_unittest(IOTest, BytesIOTest, StringIOTest,
......
......@@ -98,7 +98,6 @@ class urlopen_FileTests(unittest.TestCase):
class ProxyTests(unittest.TestCase):
def setUp(self):
unittest.TestCase.setUp(self)
# Save all proxy related env vars
self._saved_environ = dict([(k, v) for k, v in os.environ.iteritems()
if k.lower().find('proxy') >= 0])
......@@ -107,9 +106,8 @@ class ProxyTests(unittest.TestCase):
del os.environ[k]
def tearDown(self):
unittest.TestCase.tearDown(self)
# Restore all proxy related env vars
for k, v in self._saved_environ:
for k, v in self._saved_environ.iteritems():
os.environ[k] = v
def test_getproxies_environment_keep_no_proxies(self):
......
......@@ -61,7 +61,7 @@ class XrangeTest(unittest.TestCase):
def test_pickling(self):
testcases = [(13,), (0, 11), (-22, 10), (20, 3, -1),
(13, 21, 3), (-2, 2, 2)]
for proto in range(pickle.HIGHEST_PROTOCOL):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
for t in testcases:
r = xrange(*t)
self.assertEquals(list(pickle.loads(pickle.dumps(r, proto))),
......
......@@ -49,6 +49,8 @@ Library
- Issue #4092: Return ArgInfo as promised in the documentation from
inspect.getargvalues.
- Issue #3935: Properly support list subclasses in bisect's C implementation.
- Issue #4014: Don't claim that Python has an Alpha release status, in addition
to claiming it is Mature.
......
......@@ -82,7 +82,7 @@ insort_right(PyObject *self, PyObject *args, PyObject *kw)
index = internal_bisect_right(list, item, lo, hi);
if (index < 0)
return NULL;
if (PyList_Check(list)) {
if (PyList_CheckExact(list)) {
if (PyList_Insert(list, index, item) < 0)
return NULL;
} else {
......@@ -183,7 +183,7 @@ insort_left(PyObject *self, PyObject *args, PyObject *kw)
index = internal_bisect_left(list, item, lo, hi);
if (index < 0)
return NULL;
if (PyList_Check(list)) {
if (PyList_CheckExact(list)) {
if (PyList_Insert(list, index, item) < 0)
return NULL;
} else {
......
......@@ -251,7 +251,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
self->closefd = 1;
if (!closefd) {
PyErr_SetString(PyExc_ValueError,
"Cannot use closefd=True with file name");
"Cannot use closefd=False with file name");
goto error;
}
......
......@@ -179,11 +179,13 @@ raise_errmsg(char *msg, PyObject *s, Py_ssize_t end)
errmsg_fn = PyObject_GetAttrString(decoder, "errmsg");
if (errmsg_fn == NULL)
return;
Py_XDECREF(decoder);
Py_DECREF(decoder);
}
pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
if (pymsg) {
PyErr_SetObject(PyExc_ValueError, pymsg);
Py_DECREF(pymsg);
}
/*
def linecol(doc, pos):
......@@ -269,6 +271,7 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict)
goto bail;
}
if (PyList_Append(chunks, chunk)) {
Py_DECREF(chunk);
goto bail;
}
Py_DECREF(chunk);
......@@ -370,6 +373,7 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict)
goto bail;
}
if (PyList_Append(chunks, chunk)) {
Py_DECREF(chunk);
goto bail;
}
Py_DECREF(chunk);
......@@ -379,8 +383,7 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict)
if (rval == NULL) {
goto bail;
}
Py_DECREF(chunks);
chunks = NULL;
Py_CLEAR(chunks);
return Py_BuildValue("(Nn)", rval, end);
bail:
Py_XDECREF(chunks);
......@@ -429,6 +432,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict)
goto bail;
}
if (PyList_Append(chunks, chunk)) {
Py_DECREF(chunk);
goto bail;
}
Py_DECREF(chunk);
......@@ -530,6 +534,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict)
goto bail;
}
if (PyList_Append(chunks, chunk)) {
Py_DECREF(chunk);
goto bail;
}
Py_DECREF(chunk);
......@@ -539,8 +544,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict)
if (rval == NULL) {
goto bail;
}
Py_DECREF(chunks);
chunks = NULL;
Py_CLEAR(chunks);
return Py_BuildValue("(Nn)", rval, end);
bail:
Py_XDECREF(chunks);
......
......@@ -2065,12 +2065,12 @@ PyDoc_STRVAR(setdefault_doc__,
"D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D");
PyDoc_STRVAR(pop__doc__,
"D.pop(k[,d]) -> v, remove specified key and return the corresponding value\n\
"D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n\
If key is not found, d is returned if given, otherwise KeyError is raised");
PyDoc_STRVAR(popitem__doc__,
"D.popitem() -> (k, v), remove and return some (key, value) pair as a\n\
2-tuple; but raise KeyError if D is empty");
2-tuple; but raise KeyError if D is empty.");
PyDoc_STRVAR(keys__doc__,
"D.keys() -> list of D's keys");
......@@ -2082,8 +2082,10 @@ PyDoc_STRVAR(values__doc__,
"D.values() -> list of D's values");
PyDoc_STRVAR(update__doc__,
"D.update(E, **F) -> None. Update D from E and F: for k in E: D[k] = E[k]\n\
(if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k] = F[k]");
"D.update(E, **F) -> None. Update D from dict/iterable E and F.\n"
"If E has a .keys() method, does: for k in E: D[k] = E[k]\n\
If E lacks .keys() method, does: for (k, v) in E: D[k] = v\n\
In either case, this is followed by: for k in F: D[k] = F[k]");
PyDoc_STRVAR(fromkeys__doc__,
"dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.\n\
......
......@@ -824,12 +824,30 @@ static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
return 0;
}
static int add_ast_fields(void)
{
PyObject *empty_tuple, *d;
if (PyType_Ready(&AST_type) < 0)
return -1;
d = AST_type.tp_dict;
empty_tuple = PyTuple_New(0);
if (!empty_tuple ||
PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
Py_XDECREF(empty_tuple);
return -1;
}
Py_DECREF(empty_tuple);
return 0;
}
""", 0, reflow=False)
self.emit("static int init_types(void)",0)
self.emit("{", 0)
self.emit("static int initialized;", 1)
self.emit("if (initialized) return 1;", 1)
self.emit("if (add_ast_fields() < 0) return 0;", 1)
for dfn in mod.dfns:
self.visit(dfn)
self.emit("initialized = 1;", 1)
......
......@@ -615,11 +615,29 @@ static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
return 0;
}
static int add_ast_fields(void)
{
PyObject *empty_tuple, *d;
if (PyType_Ready(&AST_type) < 0)
return -1;
d = AST_type.tp_dict;
empty_tuple = PyTuple_New(0);
if (!empty_tuple ||
PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
Py_XDECREF(empty_tuple);
return -1;
}
Py_DECREF(empty_tuple);
return 0;
}
static int init_types(void)
{
static int initialized;
if (initialized) return 1;
if (add_ast_fields() < 0) return 0;
mod_type = make_type("mod", &AST_type, NULL, 0);
if (!mod_type) return 0;
if (!add_attributes(mod_type, NULL, 0)) return 0;
......
......@@ -12,7 +12,7 @@ import sys, os, re, getopt
# our pysource module finds Python source files
try:
import pysource
except:
except ImportError:
# emulate the module with a simple os.walk
class pysource:
has_python_ext = looks_like_python = can_be_compiled = None
......
......@@ -99,7 +99,8 @@ def check(file):
for name in names:
fullname = os.path.join(file, name)
if ((recurse and os.path.isdir(fullname) and
not os.path.islink(fullname))
not os.path.islink(fullname) and
not os.path.split(fullname)[1].startswith("."))
or name.lower().endswith(".py")):
check(fullname)
return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment