Closed moorepants closed 5 months ago
Maybe this issue should have been open in the main jedi repo, as I see that it also affects Spyder (note the different function signatures shown in the console and the hover popup):
The signature comes from https://github.com/matplotlib/matplotlib/blob/b3d29fb036b0d9de2fb66ee7bcad6887654b3706/lib/matplotlib/animation.pyi#L205
I personally think that these signatures are in general very helpful. Even in this context I feel like I would prefer it. This is the signature that matplotlib devs guarantee us (and it is probably type checked internally).
We could potentially come up with a configuration option that disables type annotations in these strings, but I don't like to support that and it's quite a bit of extra work, so I will simply close this issue. I appreciate the way how you asked for this, but this is probably a minority opinion if you consider all cases and not just matplotlib and it's just extra work and maintenance that I don't like to do. Sorry.
FYI: If you want a very quick workaround, you can simply delete the relevant .pyi
files. This might however have other consequences for type inference.
Thanks for your consideration.
I know you've closed this but I came across this in NumPy's linspace function (from shift + K) and felt it was at least worth reporting:
Docstring for function numpy.core.function_base.linspace
========================================================
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[complexfloating[Any, Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: _DTypeLike[_SCT]=..., axis: SupportsIndex=...) -> NDArray[_SCT]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: DTypeLike=..., axis: SupportsIndex=...) -> NDArray[Any]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: None=..., axis: SupportsIndex=...) -> tuple[NDArray[floating[Any]], floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: None=..., axis: SupportsIndex=...) -> tuple[NDArray[complexfloating[Any, Any]], complexfloating[Any, Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: _DTypeLike[_SCT]=..., axis: SupportsIndex=...) -> tuple[NDArray[_SCT], _SCT]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: DTypeLike=..., axis: SupportsIndex=...) -> tuple[NDArray[Any], Any]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[complexfloating[Any, Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: _DTypeLike[_SCT]=..., axis: SupportsIndex=...) -> NDArray[_SCT]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: DTypeLike=..., axis: SupportsIndex=...) -> NDArray[Any]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: None=..., axis: SupportsIndex=...) -> tuple[NDArray[floating[Any]], floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: None=..., axis: SupportsIndex=...) -> tuple[NDArray[complexfloating[Any, Any]], complexfloating[Any, Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: _DTypeLike[_SCT]=..., axis: SupportsIndex=...) -> tuple[NDArray[_SCT], _SCT]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[complexfloating[Any, Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: _DTypeLike[_SCT]=..., axis: SupportsIndex=...) -> NDArray[_SCT]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: DTypeLike=..., axis: SupportsIndex=...) -> NDArray[Any]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: None=..., axis: SupportsIndex=...) -> tuple[NDArray[floating[Any]], floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: None=..., axis: SupportsIndex=...) -> tuple[NDArray[complexfloating[Any, Any]], complexfloating[Any, Any]]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[complexfloating[Any, Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: _DTypeLike[_SCT]=..., axis: SupportsIndex=...) -> NDArray[_SCT]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: DTypeLike=..., axis: SupportsIndex=...) -> NDArray[Any]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[True]=..., dtype: None=..., axis: SupportsIndex=...) -> tuple[NDArray[floating[Any]], floating[Any]]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[complexfloating[Any, Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: _DTypeLike[_SCT]=..., axis: SupportsIndex=...) -> NDArray[_SCT]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: DTypeLike=..., axis: SupportsIndex=...) -> NDArray[Any]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[complexfloating[Any, Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: _DTypeLike[_SCT]=..., axis: SupportsIndex=...) -> NDArray[_SCT]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[floating[Any]]
linspace(start: _ArrayLikeComplex_co, stop: _ArrayLikeComplex_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[complexfloating[Any, Any]]
linspace(start: _ArrayLikeFloat_co, stop: _ArrayLikeFloat_co, num: SupportsIndex=..., endpoint: bool=..., retstep: L[False]=..., dtype: None=..., axis: SupportsIndex=...) -> NDArray[floating[Any]]
Return evenly spaced numbers over a specified interval.
Returns `num` evenly spaced samples, calculated over the
interval [`start`, `stop`].
The endpoint of the interval can optionally be excluded.
.. versionchanged:: 1.16.0
Non-scalar `start` and `stop` are now supported.
.. versionchanged:: 1.20.0
Values are rounded towards ``-inf`` instead of ``0`` when an
integer ``dtype`` is specified. The old behavior can
still be obtained with ``np.linspace(start, stop, num).astype(int)``
...
The first 38 lines are not so easy to read and the popup that occurs when typing the linspace function also shows these lines.
This can be compared with the doctring shown with help()
:
linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0, *, device=None)
Return evenly spaced numbers over a specified interval.
Returns `num` evenly spaced samples, calculated over the
interval [`start`, `stop`].
...
Thanks for letting me know.
Issue
jedi-vim seems to include type logic in the function signature of the docstring when it should not* be present.
*probably depends on opinion
Steps to reproduce
install matplotlib
In a Python file in vim type:
shift-K on
FuncAnimation()
to view its docstring. This displays:Open Python and type:
This displays:
Note that matplotlib does not display the complex type logic in their docstring, which keeps it readable (IMHO). It seems that jedi-vim may inject a different function signature (not sure, just a guess).
I would prefer to see what
help()
shows, in this case. Can we disable overwriting function signatures with type logic? Or maybe this is unintentional on jedi-vim's side?You can see that matplotlib does not include this in their docstring here:
https://github.com/matplotlib/matplotlib/blob/5b36d02f796e212c44932c37ed75a0655473f3ac/lib/matplotlib/animation.py#L1527
Note that this more complex type logic also is displayed in the jedi-vim popups that show the function signature. In that case, it is even more difficult to make sense of since it makes the function signature so long and the popup only displays the first characters of it.
Output of “:verbose JediDebugInfo”
You should run this in a buffer with filetype "python".
Jedi-vim debug information
jedi-vim version
Global Python
Using Python version 3 to access Jedi.
/home/moorepants/miniconda/bin/python3
3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0]
/usr/lib/python3.12/site.py
Jedi
/home/moorepants/.vim/bundle/jedi-vim/pythonx/jedi/jedi/__init__.py
Jedi environment: <SameEnvironment: 3.11.8 in /home/moorepants/miniconda>
/home/moorepants/miniconda/lib/python311.zip
/home/moorepants/miniconda/lib/python3.11
/home/moorepants/miniconda/lib/python3.11/lib-dynload
/home/moorepants/miniconda/lib/python3.11/site-packages
Known environments
<Environment: 3.12.3 in /usr> (/usr/bin/python3.12)
<Environment: 3.11.8 in /home/moorepants/miniconda> (/home/moorepants/miniconda/bin/python3.11)
Settings
:version
:messages
:scriptnames
``` 1: /etc/vim/vimrc 2: /usr/share/vim/vim91/debian.vim 3: /usr/share/vim/vim91/syntax/syntax.vim 4: /usr/share/vim/vim91/syntax/synload.vim 5: /usr/share/vim/vim91/syntax/syncolor.vim 6: /usr/share/vim/vim91/colors/lists/default.vim 7: /usr/share/vim/vim91/filetype.vim 8: /usr/share/vim/vim91/syntax/python.vim 9: ~/.vimrc 10: /usr/share/vim/vim91/ftoff.vim 11: ~/.vim/bundle/Vundle.vim/autoload/vundle.vim 12: ~/.vim/bundle/Vundle.vim/autoload/vundle/config.vim 13: /usr/share/vim/vim91/syntax/nosyntax.vim 14: ~/.vim/bundle/vimtex/ftdetect/cls.vim 15: ~/.vim/bundle/vimtex/ftdetect/tex.vim 16: ~/.vim/bundle/vimtex/ftdetect/tikz.vim 17: ~/.vim/bundle/vim-pcgen/ftdetect/pcgen.vim 18: ~/.vim/bundle/vim-fugitive/ftdetect/fugitive.vim 19: ~/.vim/bundle/python-mode/syntax/python.vim 20: ~/.vim/bundle/python-mode/autoload/pymode.vim 21: ~/.vim/bundle/jedi-vim/after/syntax/python.vim 22: ~/.vim/bundle/jedi-vim/autoload/jedi.vim 23: /usr/share/vim/vim91/ftplugin.vim 24: /usr/share/vim/vim91/indent.vim 25: ~/.vim/bundle/jedi-vim/plugin/jedi.vim 26: ~/.vim/bundle/vim-slime/plugin/slime.vim 27: ~/.vim/bundle/vim-slime/autoload/slime/config.vim 28: ~/.vim/bundle/vimtex/plugin/vimtex.vim 29: ~/.vim/bundle/vim-jinja/plugin/htmljinja.vim 30: ~/.vim/bundle/nerdtree/plugin/NERD_tree.vim 31: ~/.vim/bundle/nerdtree/autoload/nerdtree.vim 32: ~/.vim/bundle/nerdtree/lib/nerdtree/path.vim 33: ~/.vim/bundle/nerdtree/lib/nerdtree/menu_controller.vim 34: ~/.vim/bundle/nerdtree/lib/nerdtree/menu_item.vim 35: ~/.vim/bundle/nerdtree/lib/nerdtree/key_map.vim 36: ~/.vim/bundle/nerdtree/lib/nerdtree/bookmark.vim 37: ~/.vim/bundle/nerdtree/lib/nerdtree/tree_file_node.vim 38: ~/.vim/bundle/nerdtree/lib/nerdtree/tree_dir_node.vim 39: ~/.vim/bundle/nerdtree/lib/nerdtree/opener.vim 40: ~/.vim/bundle/nerdtree/lib/nerdtree/creator.vim 41: ~/.vim/bundle/nerdtree/lib/nerdtree/flag_set.vim 42: ~/.vim/bundle/nerdtree/lib/nerdtree/nerdtree.vim 43: ~/.vim/bundle/nerdtree/lib/nerdtree/ui.vim 44: ~/.vim/bundle/nerdtree/lib/nerdtree/event.vim 45: ~/.vim/bundle/nerdtree/lib/nerdtree/notifier.vim 46: ~/.vim/bundle/nerdtree/autoload/nerdtree/ui_glue.vim 47: ~/.vim/bundle/nerdtree/nerdtree_plugin/exec_menuitem.vim 48: ~/.vim/bundle/nerdtree/nerdtree_plugin/fs_menu.vim 49: ~/.vim/bundle/nerdtree/nerdtree_plugin/vcs.vim 50: ~/.vim/bundle/python-mode/plugin/pymode.vim 51: ~/.vim/bundle/vim-fugitive/plugin/fugitive.vim 52: ~/.vim/bundle/ToggleComment/plugin/ToggleComment.vim 53: ~/.vim/bundle/taglist.vim/plugin/taglist.vim 54: /usr/share/vim/vim91/plugin/getscriptPlugin.vim 55: /usr/share/vim/vim91/plugin/gzip.vim 56: /usr/share/vim/vim91/plugin/logiPat.vim 57: /usr/share/vim/vim91/plugin/manpager.vim 58: /usr/share/vim/vim91/plugin/matchparen.vim 59: /usr/share/vim/vim91/plugin/netrwPlugin.vim 60: /usr/share/vim/vim91/plugin/rrhelper.vim 61: /usr/share/vim/vim91/plugin/spellfile.vim 62: /usr/share/vim/vim91/plugin/tarPlugin.vim 63: /usr/share/vim/vim91/plugin/tohtml.vim 64: /usr/share/vim/vim91/plugin/vimballPlugin.vim 65: /usr/share/vim/vim91/plugin/zipPlugin.vim 66: ~/.vim/bundle/jedi-vim/ftplugin/python/jedi.vim 67: ~/.vim/bundle/vim-slime/ftplugin/python/slime.vim 68: ~/.vim/bundle/python-mode/ftplugin/python/pymode.vim 69: ~/.vim/bundle/python-mode/autoload/pymode/virtualenv.vim 70: ~/.vim/bundle/python-mode/autoload/pymode/breakpoint.vim 71: /usr/share/vim/vim91/ftplugin/python.vim 72: ~/.vim/after/ftplugin/python.vim 73: ~/.vim/bundle/jedi-vim/after/ftplugin/python/jedi.vim 74: ~/.vim/bundle/python-mode/after/ftplugin/python.vim 75: /usr/share/vim/vim91/indent/python.vim 76: ~/.vim/bundle/python-mode/after/indent/python.vim 77: ~/.vim/bundle/python-mode/autoload/pymode/lint.vim 78: ~/.vim/bundle/python-mode/autoload/pymode/tools/signs.vim 79: ~/.vim/bundle/python-mode/autoload/pymode/tools/loclist.vim 80: /usr/share/vim/vim91/scripts.vim 81: /usr/share/vim/vim91/autoload/dist/script.vim 82: /usr/share/vim/vim91/syntax/rst.vim 83: /usr/share/vim/vim91/syntax/vim.vim 84: /usr/share/vim/vim91/syntax/lua.vim 85: /usr/share/vim/vim91/syntax/perl.vim 86: /usr/share/vim/vim91/syntax/pod.vim 87: /usr/share/vim/vim91/syntax/ruby.vim 88: /usr/share/vim/vim91/syntax/sh.vim 89: /usr/share/vim/vim91/syntax/php.vim 90: /usr/share/vim/vim91/syntax/html.vim 91: /usr/share/vim/vim91/syntax/xml.vim 92: /usr/share/vim/vim91/syntax/dtd.vim 93: /usr/share/vim/vim91/syntax/javascript.vim 94: /usr/share/vim/vim91/syntax/vb.vim 95: /usr/share/vim/vim91/syntax/css.vim 96: /usr/share/vim/vim91/syntax/sql.vim 97: /usr/share/vim/vim91/syntax/sqloracle.vim 98: /usr/share/vim/vim91/syntax/java.vim 99: /usr/share/vim/vim91/syntax/cpp.vim 100: /usr/share/vim/vim91/syntax/c.vim 101: /usr/share/vim/vim91/syntax/lisp.vim 102: ~/.vim/bundle/vim-slime/ftplugin/rst/slime.vim 103: /usr/share/vim/vim91/ftplugin/rst.vim 104: ~/.vim/after/ftplugin/rst.vim 105: /usr/share/vim/vim91/indent/rst.vim 106: /usr/share/vim/vim91/ftplugin/vim.vim 107: /usr/share/vim/vim91/indent/vim.vim 108 A: /usr/share/vim/vim91/autoload/dist/vimindent.vim ```