Sander Stoks - 2015-03-14

When you use a PythonQt NicePyConsole or SimpleConsole and try to use the interactive help system, you get an error:

help()

Welcome to Python 3.4's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.4/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> print
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/_sitebuiltins.py", line 103, in call
return pydoc.help(args, *kwds)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pydoc.py", line 1820, in call
self.interact()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pydoc.py", line 1838, in interact
self.help(request)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pydoc.py", line 1865, in help
elif request: doc(request, 'Help on %s:', output=self._output)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pydoc.py", line 1603, in doc
pager(render_doc(thing, title, forceload))
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pydoc.py", line 1410, in pager
pager = getpager()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pydoc.py", line 1417, in getpager
if not sys.stdin.isatty() or not sys.stdout.isatty():
AttributeError: 'PythonQtStdInRedirect' object has no attribute ‘isatty'</module></string>

The following patch adds the isatty() method to PythonQtStdInRedirect, after which the above example works perfectly:

Index: src/PythonQtStdIn.cpp

--- src/PythonQtStdIn.cpp (revision 392)
+++ src/PythonQtStdIn.cpp (working copy)
@@ -61,9 +61,16 @@
return Py_BuildValue("s", string.toLatin1().constData());
}

+static PyObject PythonQtStdInRedirect_isatty(PyObject * /self/)
+{
+ Py_RETURN_TRUE;
+}
+
static PyMethodDef PythonQtStdInRedirect_methods[] = {
{"readline", (PyCFunction)PythonQtStdInRedirect_readline, METH_VARARGS,
"read input line"},
+ {"isatty", (PyCFunction)PythonQtStdInRedirect_isatty, METH_NOARGS,
+ "is this a tty"},
{NULL, NULL, 0 , NULL} /
sentinel */
};

I read somewhere else that the preferred way of submitting patches was to enter a bug and attach the patch, but I’m getting a “permission denied” when I try to open a new bug in the tracker. I hope just posting it here is acceptable too.

Regards,
Sander