【问题标题】:Where does VSCode get the docstring signature?VSCode 从哪里获取文档字符串签名?
【发布时间】:2020-08-18 14:38:59
【问题描述】:

VSCode 从哪里获取文档字符串签名?我在设置中找不到任何相关部分。

在我的安装中,很明显 VSCode 没有使用来自 __doc__ 属性的签名。 我想查看__doc__(或将其设置为pydoc 的输出),但我得到如下内容

这是我从__doc__pydoc 得到的签名

print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)

【问题讨论】:

  • In: print.__doc__ Out: "print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\nOptional keyword arguments:\nfile: a file-like object (stream); defaults to the current sys.stdout.\nsep: string inserted between values, default a space.\nend: string appended after the last value, default a newline.\nflush: whether to forcibly flush the stream." 这是我从print.__doc__ 得到的。也许 VSCode 正在使用不同的 python 安装?
  • @PranavHosangadi 是的,我已经检查过了,我使用相同的 Python 解释器 VSCode 设置为 (/usr/local/bin/python3)。当您将鼠标悬停在 VSCode 中时,您会得到与 print.__doc__ 相同的输出还是得到类似我的屏幕截图的输出?
  • 它是什么版本的 Python?可能是特定于版本或平台的东西?
  • @PranavHosangadi 我尝试了两种不同的系统,一种是 3.6,另一种是 3.7,结果相同。

标签: python-3.x visual-studio-code docstring


【解决方案1】:

它看起来像是从 mypy 的存根文件以及部分文档字符串中提取它们。

内置函数和标准库的存根文件可以在以下位置找到。 <python path>\Lib\site-packages\mypy\typeshed\stdlib\。打印语句可以在2 文件夹中的__builtin__.pyi 中找到,该文件夹围绕1354 行。

if sys.version_info >= (3,):
    class _Writer(Protocol):
        def write(self, __s: str) -> Any: ...
    def print(
        *values: object, sep: Optional[Text] = ..., end: Optional[Text] = ..., file: Optional[_Writer] = ..., flush: bool = ...
    ) -> None: ...

Github 链接到相关行。这是一个较新的版本,因此并不完全相同。

【讨论】:

    猜你喜欢
    • 2016-09-18
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 2011-10-05
    • 2023-03-17
    • 2019-11-10
    • 2021-12-14
    • 1970-01-01
    相关资源
    最近更新 更多