Skip to content

Commit

Permalink
Use pydoc instead of interactive 'help()'
Browse files Browse the repository at this point in the history
Also fix the tests
  • Loading branch information
galaunay committed Apr 6, 2019
1 parent da86ea3 commit 925756f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
3 changes: 1 addition & 2 deletions elpy.el
Original file line number Diff line number Diff line change
Expand Up @@ -2159,8 +2159,7 @@ prefix argument is given, prompt for a symbol from the user."
(docstring
(when symbol
(python-shell-send-string-no-output
(format "\ntry:\n help(%s)\nexcept NameError:\n try:\n help('%s')\n except NameError:\n pass"
symbol symbol)
(format "import pydoc, io\noutput = io.StringIO()\nh = pydoc.Helper(output=output)\nh.help(%s)\nprint(output.getvalue())" symbol)
process))))
(unless (or (zerop (length docstring))
(string-match "Traceback (most recent call last):"
Expand Down
22 changes: 14 additions & 8 deletions test/elpy-doc-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,21 @@
(python-mode)
(elpy-mode)
(let ((elpy-get-info-from-shell t)
(elpy-get-info-from-shell-timeout 10)
(elpy-get-info-from-shell-timeout 1)
(python-shell-completion-native-enable nil))
(elpy-shell-get-or-create-process)
(message "python: %s" (python-shell-send-string-no-output "def foo(a, b):\n \"\"\"Foo doc\"\"\"\n return a + b"))
(message "python: %s" (python-shell-send-string-no-output "foo(1, 2)"))
(message "python: %s" (python-shell-send-string-no-output "help()"))
(message "python: %s" (python-shell-send-string-no-output "help(foo)"))
(insert "foo")
(message "doc: %s" (elpy-doc-get-docstring-from-shell))
(python-shell-send-string "def foo(a, b):\n \"\"\"Foo doc\"\"\"\n return a + b")
(python-shell-send-string "import os.path")
(python-shell-send-string "print('DONE')")
(with-current-buffer "*Python*"
(elpy/wait-for-output "DONE"))
;; Get doc for 'foo'
(insert "\nfoo")
(elpy-doc)
(with-current-buffer "*Python Doc*"
(should (re-search-forward "Foo doc"))))))
(should (re-search-forward "Foo doc")))
;; Get doc for 'os.path'
(insert "\nos.path")
(elpy-doc)
(with-current-buffer "*Python Doc*"
(should (re-search-forward "Help on module posixpath"))))))

0 comments on commit 925756f

Please sign in to comment.