question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Show doc-string of function

See original GitHub issue

I’m using the following settings in coc (from the coc README) to show documentation when pressing K:

" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>

function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  elseif (coc#rpc#ready())
    call CocActionAsync('doHover')
  else
    execute '!' . &keywordprg . " " . expand('<cword>')
  endif
endfunction

Previously I used coc-python which then showed the doc-string of the function. However with coc-pyright I’m just getting the signature of the function which in some cases is totally unusable. For example if I press K when on subprocess.run I get the monstrosity

(function) run: Overload[(args: _CMD, bufsize: int = ..., executable: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn:      
 () -> Any = ..., close_fds: bool = ..., shell: bool = ..., cwd: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., env: Mapping[bytes, _TXT] | Mapping[str, _TXT] | None = ..., universal_newlines:     
 bool = ..., startupinfo: Any = ..., creationflags: int = ..., restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., *, capture_output: bool = ..., check: bool = ..., encoding: str |   
 None = ..., errors: str | None = ..., input: str | None = ..., text: Literal[True], timeout: float | None = ...) -> CompletedProcess[str], (args: _CMD, bufsize: int = ..., executable: str | bytes |              
 _PathLike[str] | _PathLike[bytes] | None = ..., stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: () -> Any = ..., close_fds: bool = ..., shell: bool = ..., cwd: str | bytes |            
 _PathLike[str] | _PathLike[bytes] | None = ..., env: Mapping[bytes, _TXT] | Mapping[str, _TXT] | None = ..., universal_newlines: bool = ..., startupinfo: Any = ..., creationflags: int = ..., restore_signals:    
 bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., *, capture_output: bool = ..., check: bool = ..., encoding: str, errors: str | None = ..., input: str | None = ..., text: bool | None = ...,       
 timeout: float | None = ...) -> CompletedProcess[str], (args: _CMD, bufsize: int = ..., executable: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., stdin: _FILE = ..., stdout: _FILE = ...,         
 stderr: _FILE = ..., preexec_fn: () -> Any = ..., close_fds: bool = ..., shell: bool = ..., cwd: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., env: Mapping[bytes, _TXT] | Mapping[str, _TXT] |    
 None = ..., universal_newlines: bool = ..., startupinfo: Any = ..., creationflags: int = ..., restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., *, capture_output: bool = ...,      
 check: bool = ..., encoding: str | None = ..., errors: str, input: str | None = ..., text: bool | None = ..., timeout: float | None = ...) -> CompletedProcess[str], (args: _CMD, bufsize: int = ...,              
 executable: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: () -> Any = ..., close_fds: bool = ..., shell: bool = ...,     
 cwd: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., env: Mapping[bytes, _TXT] | Mapping[str, _TXT] | None = ..., *, universal_newlines: Literal[True], startupinfo: Any = ..., creationflags: int   
 = ..., restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., capture_output: bool = ..., check: bool = ..., encoding: str | None = ..., errors: str | None = ..., input: str | None     
 = ..., text: bool | None = ..., timeout: float | None = ...) -> CompletedProcess[str], (args: _CMD, bufsize: int = ..., executable: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., stdin: _FILE     
 = ..., stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: () -> Any = ..., close_fds: bool = ..., shell: bool = ..., cwd: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., env: Mapping[bytes,     
 _TXT] | Mapping[str, _TXT] | None = ..., universal_newlines: Literal[False] = ..., startupinfo: Any = ..., creationflags: int = ..., restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any     
 = ..., *, capture_output: bool = ..., check: bool = ..., encoding: None = ..., errors: None = ..., input: bytes | None = ..., text: Literal[False] | None = ..., timeout: float | None = ...) ->                   
 CompletedProcess[bytes], (args: _CMD, bufsize: int = ..., executable: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn:      
 () -> Any = ..., close_fds: bool = ..., shell: bool = ..., cwd: str | bytes | _PathLike[str] | _PathLike[bytes] | None = ..., env: Mapping[bytes, _TXT] | Mapping[str, _TXT] | None = ..., universal_newlines:     
 bool = ..., startupinfo: Any = ..., creationflags: int = ..., restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., *, capture_output: bool = ..., check: bool = ..., encoding: str |   
 None = ..., errors: str | None = ..., input: bytes | str | None = ..., text: bool | None = ..., timeout: float | None = ...) -> CompletedProcess[Any]]   

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

0reactions
AckslDcommented, Feb 11, 2021

@meandmymind I had a hack previously for earlier version of coc-python to get the correct python path for virtual environments. However, now I just set it back to:

    "python.pythonPath": "python",

and things worked

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting the docstring from a function - python - Stack Overflow
Interactively, you can display it with help(my_func). Or from code you can retrieve it with (surround it with print(.) to get a formatted...
Read more >
Python Docstrings (With Examples) - Programiz
Python docstrings are the string literals that appear right after the definition of a function, method, class, or module. Let's take an example....
Read more >
Python Docstrings - GeeksforGeeks
Python documentation strings (or docstrings) provide a convenient way of associating documentation with Python modules, functions, classes, ...
Read more >
Python Docstrings Tutorial : Examples & Format for Pydoc ...
Python documentation string or commonly known as docstring, is a string literal, and it is used in the class, module, function, or method...
Read more >
Python Docstring: Documenting And Introspecting Functions
This tutorial explains what is Python Docstring and how to use it to document Python functions with examples.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found