From 9929bc543a014f3c7f764d79a614fc8a9751d7ce Mon Sep 17 00:00:00 2001 From: R David Murray Date: Tue, 19 Mar 2013 02:31:06 -0400 Subject: [PATCH 1/6] #17476: make allmethods actually return all methods. This fixes a regression relative to Python2. (In 2, methods on a class were unbound methods and matched the inspect queries being done, in 3 they are just functions and so were missed). This is an undocumented function that pydoc itself does not use, but I found that numpy at least uses it in its documentation generator. Original patch by Matt Bachmann. --- Lib/pydoc.py | 5 ++++- Lib/test/test_pydoc.py | 24 ++++++++++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 37616fb3edd..fa02edaffca 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -137,7 +137,10 @@ def stripid(text): return _re_stripid.sub(r'\1', text) def _is_some_method(obj): - return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj) + return (inspect.isfunction(obj) or + inspect.ismethod(obj) or + inspect.isbuiltin(obj) or + inspect.ismethoddescriptor(obj)) def allmethods(cl): methods = {} diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index c7318ff613e..42a4089940c 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -389,6 +389,30 @@ class PydocDocTest(unittest.TestCase): synopsis = pydoc.synopsis(TESTFN, {}) self.assertEqual(synopsis, 'line 1: h\xe9') + def test_allmethods(self): + # issue 17476: allmethods was no longer returning unbound methods. + # This test is a bit fragile in the face of changes to object and type, + # but I can't think of a better way to do it without duplicating the + # logic of the function under test. + + class TestClass(object): + def method_returning_true(self): + return True + + # What we expect to get back: everything on object... + expected = dict(vars(object)) + # ...plus our unbound method... + expected['method_returning_true'] = TestClass.method_returning_true + # ...but not the non-methods on object. + del expected['__doc__'] + del expected['__class__'] + # inspect resolves descriptors on type into methods, but vars doesn't, + # so we need to update __subclasshook__. + expected['__subclasshook__'] = TestClass.__subclasshook__ + + methods = pydoc.allmethods(TestClass) + self.assertDictEqual(methods, expected) + class PydocImportTest(unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS index af2231821bc..5e36c4215b1 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -233,6 +233,9 @@ Core and Builtins Library ------- +- Issue #17476: Fixed regression relative to Python2 in undocumented pydoc + 'allmethods'; it was missing unbound methods on the class. + - Issue #16389: Fixed a performance regression relative to Python 3.1 in the caching of compiled regular expressions. From 0492ec07e00ac85184c50d3dfad44b3b8d173614 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Tue, 19 Mar 2013 00:51:08 -0700 Subject: [PATCH 2/6] #17460 - Adding relevant warning messages regarding strict removal in docs --- Doc/library/http.client.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/http.client.rst b/Doc/library/http.client.rst index 408a3e7bb0f..7423a4cd361 100644 --- a/Doc/library/http.client.rst +++ b/Doc/library/http.client.rst @@ -51,7 +51,7 @@ The module provides the following classes: .. versionchanged:: 3.2 *source_address* was added. - .. versionchanged:: 3.2 + .. deprecated:: 3.2 The *strict* parameter is deprecated. HTTP 0.9-style "Simple Responses" are not supported anymore. @@ -89,7 +89,7 @@ The module provides the following classes: This class now supports HTTPS virtual hosts if possible (that is, if :data:`ssl.HAS_SNI` is true). - .. versionchanged:: 3.2 + .. deprecated:: 3.2 The *strict* parameter is deprecated. HTTP 0.9-style "Simple Responses" are not supported anymore. @@ -99,7 +99,7 @@ The module provides the following classes: Class whose instances are returned upon successful connection. Not instantiated directly by user. - .. versionchanged:: 3.2 + .. deprecated:: 3.2 The *strict* parameter is deprecated. HTTP 0.9-style "Simple Responses" are not supported anymore. From ae4ef4d2ff2d49628516294837249493f43a5047 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 19 Mar 2013 13:25:20 +0200 Subject: [PATCH 3/6] Fix usage of the unittest.skip decorator. --- Lib/tkinter/test/test_ttk/test_widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/test/test_ttk/test_widgets.py b/Lib/tkinter/test/test_ttk/test_widgets.py index c2231dc3241..45a686aed4f 100644 --- a/Lib/tkinter/test/test_ttk/test_widgets.py +++ b/Lib/tkinter/test/test_ttk/test_widgets.py @@ -947,7 +947,7 @@ class TreeviewTest(unittest.TestCase): anchor=1) # XXX skipping for now; should be fixed to work with newer ttk - @unittest.skip + @unittest.skip("skipping pending resolution of Issue #10734") def test_heading_callback(self): def simulate_heading_click(x, y): support.simulate_mouse_click(self.tv, x, y) From fcb6d6a3b3bfba67927ced18dd648ba889e14f4c Mon Sep 17 00:00:00 2001 From: R David Murray Date: Tue, 19 Mar 2013 13:52:33 -0400 Subject: [PATCH 4/6] #17443: Fix buffering in IMAP4_stream. In Python2 Popen uses *FILE objects, which wind up buffering even though subprocess defaults to no buffering. In Python3, subprocess streams really are unbuffered by default, but the imaplib code assumes read is buffered. This patch uses the default buffer size from the io module to get buffered streams from Popen. Much debugging work and patch by Diane Trout. The imap protocol is too complicated to write a test for this simple change with our current level of test infrastructure. --- Lib/imaplib.py | 2 ++ Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 00a17fbf36d..e2a05818fa6 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -23,6 +23,7 @@ Public functions: Internaldate2tuple __version__ = "2.58" import binascii, errno, random, re, socket, subprocess, sys, time, calendar +from io import DEFAULT_BUFFER_SIZE try: import ssl @@ -1237,6 +1238,7 @@ class IMAP4_stream(IMAP4): self.sock = None self.file = None self.process = subprocess.Popen(self.command, + bufsize=DEFAULT_BUFFER_SIZE, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True, close_fds=True) self.writefile = self.process.stdin diff --git a/Misc/ACKS b/Misc/ACKS index b5c80592f5c..6ea3f78d76c 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1098,6 +1098,7 @@ Richard Townsend Nathan Trapuzzano Laurence Tratt John Tromp +Diane Trout Jason Trowbridge Brent Tubbs Anthony Tuininga diff --git a/Misc/NEWS b/Misc/NEWS index 5e36c4215b1..9a62a02bebe 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -233,6 +233,10 @@ Core and Builtins Library ------- +- Issue #17443: impalib.IMAP4_stream was using the default unbuffered IO + in subprocess, but the imap code assumes buffered IO. In Python2 this + worked by accident. IMAP4_stream now explicitly uses buffered IO. + - Issue #17476: Fixed regression relative to Python2 in undocumented pydoc 'allmethods'; it was missing unbound methods on the class. From f5d7cc239e61e063e7bab783d55deb8e72210674 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Tue, 19 Mar 2013 16:23:09 -0400 Subject: [PATCH 5/6] #8862: Fix curses cleanup with getchar is interrupted by a signal. I have no idea how one would write a test for this. Patch by July Tikhonov. --- Misc/NEWS | 2 ++ Modules/_cursesmodule.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index 9a62a02bebe..4ebd699c448 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -233,6 +233,8 @@ Core and Builtins Library ------- +- Issue #8862: Fixed curses cleanup when getkey is interrputed by a signal. + - Issue #17443: impalib.IMAP4_stream was using the default unbuffered IO in subprocess, but the imap code assumes buffered IO. In Python2 this worked by accident. IMAP4_stream now explicitly uses buffered IO. diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 5e1afa9894a..d1dedb0bb0a 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -895,7 +895,9 @@ PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args) } if (rtn == ERR) { /* getch() returns ERR in nodelay mode */ - PyErr_SetString(PyCursesError, "no input"); + PyErr_CheckSignals(); + if (!PyErr_Occurred()) + PyErr_SetString(PyCursesError, "no input"); return NULL; } else if (rtn<=255) { return Py_BuildValue("C", rtn); From 843fae93121ac7ac1088b0521773eff567e7b41c Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Tue, 19 Mar 2013 13:43:42 -0700 Subject: [PATCH 6/6] #17471 - Improve urllib2 test coverage. Patch contributed by Daniel Wozniak --- Lib/test/test_urllib2.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 5eab30af765..a9776ac8571 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -47,6 +47,9 @@ class TrivialTests(unittest.TestCase): for string, list in tests: self.assertEqual(urllib.request.parse_http_list(string), list) + def test_URLError_reasonstr(self): + err = urllib.error.URLError('reason') + self.assertIn(err.reason, str(err)) def test_request_headers_dict(): """