Skip to content

Commit 0289b15

Browse files
committed
Merged revisions 73004,73439,73496,73509,73529,73564,73576-73577,73595-73596,73605 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r73004 | jeffrey.yasskin | 2009-05-28 22:44:31 -0500 (Thu, 28 May 2009) | 5 lines Fix nearly all compilation warnings under Apple gcc-4.0. Tested with OPT="-g -Wall -Wstrict-prototypes -Werror" in both --with-pydebug mode and --without. There's still a batch of non-prototype warnings in Xlib.h that I don't know how to fix. ........ r73439 | benjamin.peterson | 2009-06-15 19:29:31 -0500 (Mon, 15 Jun 2009) | 1 line don't mask encoding errors when decoding a string #6289 ........ r73496 | vinay.sajip | 2009-06-21 12:37:27 -0500 (Sun, 21 Jun 2009) | 1 line Issue #6314: logging.basicConfig() performs extra checks on the "level" argument. ........ r73509 | amaury.forgeotdarc | 2009-06-22 14:33:48 -0500 (Mon, 22 Jun 2009) | 2 lines #4490 Fix sample code run by "python -m xml.sax.xmlreader" ........ r73529 | r.david.murray | 2009-06-23 13:02:46 -0500 (Tue, 23 Jun 2009) | 4 lines Fix issue 5230 by having pydoc's safeimport check to see if the import error was thrown from itself in order to decide if the module can't be found. Thanks to Lucas Prado Melo for collaborating on the fix and tests. ........ r73564 | amaury.forgeotdarc | 2009-06-25 17:29:29 -0500 (Thu, 25 Jun 2009) | 6 lines #2016 Fix a crash in function call when the **kwargs dictionary is mutated during the function call setup. This even gives a slight speedup, probably because tuple allocation is faster than PyMem_NEW. ........ r73576 | benjamin.peterson | 2009-06-26 18:37:06 -0500 (Fri, 26 Jun 2009) | 1 line document is_declared_global() ........ r73577 | benjamin.peterson | 2009-06-27 09:16:23 -0500 (Sat, 27 Jun 2009) | 1 line link to extensive generator docs in the reference manual ........ r73595 | ezio.melotti | 2009-06-27 18:45:39 -0500 (Sat, 27 Jun 2009) | 1 line stmt and setup can contain multiple statements, see #5896 ........ r73596 | ezio.melotti | 2009-06-27 19:07:45 -0500 (Sat, 27 Jun 2009) | 1 line Fixed a wrong apostrophe ........ r73605 | georg.brandl | 2009-06-28 07:10:18 -0500 (Sun, 28 Jun 2009) | 1 line Remove stray pychecker directive. ........
1 parent cd3ffe6 commit 0289b15

File tree

15 files changed

+110
-39
lines changed

15 files changed

+110
-39
lines changed

Doc/library/stdtypes.rst

+8
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,18 @@ Once an iterator's :meth:`__next__` method raises :exc:`StopIteration`, it must
583583
continue to do so on subsequent calls. Implementations that do not obey this
584584
property are deemed broken.
585585

586+
587+
.. _generator-types:
588+
589+
Generator Types
590+
---------------
591+
586592
Python's :term:`generator`\s provide a convenient way to implement the iterator
587593
protocol. If a container object's :meth:`__iter__` method is implemented as a
588594
generator, it will automatically return an iterator object (technically, a
589595
generator object) supplying the :meth:`__iter__` and :meth:`__next__` methods.
596+
More information about generators can be found in :ref:`the documentation for
597+
the yield expression <yieldexpr>`.
590598

591599

592600
.. _typesseq:

Doc/library/symtable.rst

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ Examining Symbol Tables
144144

145145
Return ``True`` if the symbol is global.
146146

147+
.. method:: is_declared_global()
148+
149+
Return ``True`` if the symbol is declared global with a global statement.
150+
147151
.. method:: is_local()
148152

149153
Return ``True`` if the symbol is local to its block.

Doc/library/timeit.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ The module defines the following public class:
2424

2525
The constructor takes a statement to be timed, an additional statement used for
2626
setup, and a timer function. Both statements default to ``'pass'``; the timer
27-
function is platform-dependent (see the module doc string). The statements may
28-
contain newlines, as long as they don't contain multi-line string literals.
27+
function is platform-dependent (see the module doc string). *stmt* and *setup*
28+
may also contain multiple statements separated by ``;`` or newlines, as long as
29+
they don't contain multi-line string literals.
2930

3031
To measure the execution time of the first statement, use the :meth:`timeit`
3132
method. The :meth:`repeat` method is a convenience to call :meth:`timeit`

Lib/email/mime/nonmultipart.py

-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414
class MIMENonMultipart(MIMEBase):
1515
"""Base class for MIME multipart/* type messages."""
1616

17-
__pychecker__ = 'unusednames=payload'
18-
1917
def attach(self, payload):
2018
# The public API prohibits attaching multiple subparts to MIMEBase
2119
# derived subtypes since none of them are, by definition, of content
2220
# type multipart/*
2321
raise errors.MultipartConversionError(
2422
'Cannot attach additional subparts to non-multipart/*')
25-
26-
del __pychecker__

Lib/pydoc.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class or function within a module or module in a package. If the
5454

5555
import sys, imp, os, re, inspect, builtins, pkgutil
5656
from reprlib import Repr
57+
from traceback import extract_tb as _extract_tb
5758
try:
5859
from collections import deque
5960
except ImportError:
@@ -292,9 +293,9 @@ def safeimport(path, forceload=0, cache={}):
292293
elif exc is SyntaxError:
293294
# A SyntaxError occurred before we could execute the module.
294295
raise ErrorDuringImport(value.filename, info)
295-
elif exc is ImportError and \
296-
str(value).lower().split()[:2] == ['no', 'module']:
297-
# The module was not found.
296+
elif exc is ImportError and _extract_tb(tb)[-1][2]=='safeimport':
297+
# The import error occurred directly in this function,
298+
# which means there is no such module in the path.
298299
return None
299300
else:
300301
# Some other error occurred during the importing process.

Lib/test/test_coding.py

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ def test_file_parse(self):
4949
unlink(TESTFN+".pyc")
5050
sys.path.pop(0)
5151

52+
def test_error_from_string(self):
53+
# See http://bugs.python.org/issue6289
54+
input = "# coding: ascii\n\N{SNOWMAN}".encode('utf-8')
55+
try:
56+
compile(input, "<string>", "exec")
57+
except SyntaxError as e:
58+
expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \
59+
"ordinal not in range(128)"
60+
self.assertTrue(str(e).startswith(expected))
61+
else:
62+
self.fail("didn't raise")
63+
5264
def test_main():
5365
test.support.run_unittest(CodingTest)
5466

Lib/test/test_extcall.py

+18
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,24 @@
243243
...
244244
TypeError: id() takes no keyword arguments
245245
246+
A corner case of keyword dictionary items being deleted during
247+
the function call setup. See <http://bugs.python.org/issue2016>.
248+
249+
>>> class Name(str):
250+
... def __eq__(self, other):
251+
... try:
252+
... del x[self]
253+
... except KeyError:
254+
... pass
255+
... return str.__eq__(self, other)
256+
... def __hash__(self):
257+
... return str.__hash__(self)
258+
259+
>>> x = {Name("a"):1, Name("b"):2}
260+
>>> def f(a, b):
261+
... print(a,b)
262+
>>> f(**x)
263+
1 2
246264
"""
247265

248266
from test import support

Lib/test/test_pydoc.py

+42
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import sys
22
import os
3+
import os.path
34
import difflib
45
import subprocess
56
import re
67
import pydoc
78
import inspect
89
import unittest
910
import test.support
11+
from contextlib import contextmanager
12+
from test.support import TESTFN, forget, rmtree, EnvironmentVarGuard
1013

1114
from test import pydoc_mod
1215

@@ -183,6 +186,9 @@ class B(builtins.object)
183186
# output pattern for missing module
184187
missing_pattern = "no Python documentation found for '%s'"
185188

189+
# output pattern for module with bad imports
190+
badimport_pattern = "problem in %s - ImportError: No module named %s"
191+
186192
def run_pydoc(module_name, *args):
187193
"""
188194
Runs pydoc on the specified module. Returns the stripped
@@ -254,6 +260,42 @@ def test_not_here(self):
254260
self.assertEqual(expected, result,
255261
"documentation for missing module found")
256262

263+
def test_badimport(self):
264+
# This tests the fix for issue 5230, where if pydoc found the module
265+
# but the module had an internal import error pydoc would report no doc
266+
# found.
267+
modname = 'testmod_xyzzy'
268+
testpairs = (
269+
('i_am_not_here', 'i_am_not_here'),
270+
('test.i_am_not_here_either', 'i_am_not_here_either'),
271+
('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'),
272+
('i_am_not_here.{}'.format(modname), 'i_am_not_here.{}'.format(modname)),
273+
('test.{}'.format(modname), modname),
274+
)
275+
276+
@contextmanager
277+
def newdirinpath(dir):
278+
os.mkdir(dir)
279+
sys.path.insert(0, dir)
280+
yield
281+
sys.path.pop(0)
282+
rmtree(dir)
283+
284+
with newdirinpath(TESTFN), EnvironmentVarGuard() as env:
285+
env['PYTHONPATH'] = TESTFN
286+
fullmodname = os.path.join(TESTFN, modname)
287+
sourcefn = fullmodname + os.extsep + "py"
288+
for importstring, expectedinmsg in testpairs:
289+
f = open(sourcefn, 'w')
290+
f.write("import {}\n".format(importstring))
291+
f.close()
292+
try:
293+
result = run_pydoc(modname).decode("ascii")
294+
finally:
295+
forget(modname)
296+
expected = badimport_pattern % (modname, expectedinmsg)
297+
self.assertEqual(expected, result)
298+
257299
def test_input_strip(self):
258300
missing_module = " test.i_am_not_here "
259301
result = str(run_pydoc(missing_module), 'ascii')

Lib/xml/sax/expatreader.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ def create_parser(*args, **kwargs):
407407
# ---
408408

409409
if __name__ == "__main__":
410-
import xml.sax
410+
import xml.sax.saxutils
411411
p = create_parser()
412-
p.setContentHandler(xml.sax.XMLGenerator())
412+
p.setContentHandler(xml.sax.saxutils.XMLGenerator())
413413
p.setErrorHandler(xml.sax.ErrorHandler())
414-
p.parse("../../../hamlet.xml")
414+
p.parse("http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml")

Misc/ACKS

+1
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ Andrew McNamara
482482
Craig McPheeters
483483
Lambert Meertens
484484
Bill van Melle
485+
Lucas Prado Melo
485486
Luke Mewburn
486487
Mike Meyer
487488
Steven Miale

Modules/_ssl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ _get_peer_alt_names (X509 *certificate) {
658658
char buf[2048];
659659
char *vptr;
660660
int len;
661-
const unsigned char *p;
661+
unsigned char *p;
662662

663663
if (certificate == NULL)
664664
return peer_alt_names;

Modules/_struct.c

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ get_long(PyObject *v, long *p)
132132

133133
/* Same, but handling unsigned long */
134134

135+
#ifndef PY_STRUCT_OVERFLOW_MASKING
135136
static int
136137
get_ulong(PyObject *v, unsigned long *p)
137138
{
@@ -152,6 +153,7 @@ get_ulong(PyObject *v, unsigned long *p)
152153
*p = x;
153154
return 0;
154155
}
156+
#endif /* PY_STRUCT_OVERFLOW_MASKING */
155157

156158
#ifdef HAVE_LONG_LONG
157159

Objects/funcobject.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,14 @@ function_call(PyObject *func, PyObject *arg, PyObject *kw)
593593
{
594594
PyObject *result;
595595
PyObject *argdefs;
596+
PyObject *kwtuple = NULL;
596597
PyObject **d, **k;
597598
Py_ssize_t nk, nd;
598599

599600
argdefs = PyFunction_GET_DEFAULTS(func);
600601
if (argdefs != NULL && PyTuple_Check(argdefs)) {
601602
d = &PyTuple_GET_ITEM((PyTupleObject *)argdefs, 0);
602-
nd = PyTuple_Size(argdefs);
603+
nd = PyTuple_GET_SIZE(argdefs);
603604
}
604605
else {
605606
d = NULL;
@@ -609,16 +610,17 @@ function_call(PyObject *func, PyObject *arg, PyObject *kw)
609610
if (kw != NULL && PyDict_Check(kw)) {
610611
Py_ssize_t pos, i;
611612
nk = PyDict_Size(kw);
612-
k = PyMem_NEW(PyObject *, 2*nk);
613-
if (k == NULL) {
614-
PyErr_NoMemory();
613+
kwtuple = PyTuple_New(2*nk);
614+
if (kwtuple == NULL)
615615
return NULL;
616-
}
616+
k = &PyTuple_GET_ITEM(kwtuple, 0);
617617
pos = i = 0;
618-
while (PyDict_Next(kw, &pos, &k[i], &k[i+1]))
618+
while (PyDict_Next(kw, &pos, &k[i], &k[i+1])) {
619+
Py_INCREF(k[i]);
620+
Py_INCREF(k[i+1]);
619621
i += 2;
622+
}
620623
nk = i/2;
621-
/* XXX This is broken if the caller deletes dict items! */
622624
}
623625
else {
624626
k = NULL;
@@ -628,13 +630,12 @@ function_call(PyObject *func, PyObject *arg, PyObject *kw)
628630
result = PyEval_EvalCodeEx(
629631
(PyCodeObject *)PyFunction_GET_CODE(func),
630632
PyFunction_GET_GLOBALS(func), (PyObject *)NULL,
631-
&PyTuple_GET_ITEM(arg, 0), PyTuple_Size(arg),
633+
&PyTuple_GET_ITEM(arg, 0), PyTuple_GET_SIZE(arg),
632634
k, nk, d, nd,
633635
PyFunction_GET_KW_DEFAULTS(func),
634636
PyFunction_GET_CLOSURE(func));
635637

636-
if (k != NULL)
637-
PyMem_DEL(k);
638+
Py_XDECREF(kwtuple);
638639

639640
return result;
640641
}

Parser/tokenizer.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -682,11 +682,8 @@ decode_str(const char *str, struct tok_state *tok)
682682
if (tok->enc != NULL) {
683683
assert(utf8 == NULL);
684684
utf8 = translate_into_utf8(str, tok->enc);
685-
if (utf8 == NULL) {
686-
PyErr_Format(PyExc_SyntaxError,
687-
"unknown encoding: %s", tok->enc);
685+
if (utf8 == NULL)
688686
return error_ret(tok);
689-
}
690687
str = PyBytes_AS_STRING(utf8);
691688
}
692689
assert(tok->decoding_buffer == NULL);

Python/compile.c

-12
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,6 @@ compiler_exit_scope(struct compiler *c)
551551

552552
}
553553

554-
/* Allocate a new "anonymous" local variable.
555-
Used by list comprehensions and with statements.
556-
*/
557-
558-
static PyObject *
559-
compiler_new_tmpname(struct compiler *c)
560-
{
561-
char tmpname[256];
562-
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", ++c->u->u_tmpname);
563-
return PyUnicode_FromString(tmpname);
564-
}
565-
566554
/* Allocate a new block and return a pointer to it.
567555
Returns NULL on error.
568556
*/

0 commit comments

Comments
 (0)