python - 如何在mypy中使用reveal_type

标签 python type-hinting mypy

我读到我可以通过使用名为 reveal_type 的函数来揭示变量的类型,但我找不到如何使用它或从哪里导入它。

最佳答案

我终于找到了如何使用它:你应该只在代码中放置和使用reveal_type,然后用mypy程序运行它。然后,它将记录一条如下所示的消息:

Revealed type is 'builtins.str*'

来自 mypy 文档:

reveal_type is only understood by mypy and doesn’t exist in Python, if you try to run your program. You’ll have to remove any reveal_type calls before you can run your code. reveal_type is always available and you don’t need to import it.

更多阅读:here .

关于python - 如何在mypy中使用reveal_type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44625422/

相关文章:

python - 如何使用 CleverTap API 通过 python 发送推送?

python - 新创建的 conda envs 是否继承了基础 env 的所有包?

python - 类型错误 : 'ABCMeta' object is not subscriptable on Callable

python - 是否可以仅键入提示一个类对象但排除子类对象?

python - mypy:返回值类型不兼容

python - 如何声明包含类的字典的类型

python - 多行标准输出刷新问题

python - 如何与 pipenv 共享虚拟环境?

Python:以 MyPy 接受的方式提示 CTypes "pointer to X"类型

python - 是时候举手 throw 了吗?