如何在mypy中使用reveal_type [英] How to use reveal_type in mypy
问题描述
我读到我可以通过使用一个名为 reveal_type
的函数来显示变量的类型,但我找不到如何使用它或从哪里导入它.
I have read that I can reveal the type of variables by using a function called reveal_type
, but I can't find how to use it or from where to import it.
推荐答案
我终于知道怎么用了:你应该把代码中的 reveal_type
放进去使用,然后运行使用 mypy
程序.然后,它会记录一条如下所示的消息:
I found out in the end how to use it: You should just put and use the reveal_type
in the code, and run it with the mypy
program. Then, it will log a message that look like this:
Revealed type is 'builtins.str*'
来自 mypy
文档:
reveal_type 只能被 mypy 理解,在 Python 中不存在,如果你试图运行你的程序.在运行代码之前,您必须删除任何reveal_type 调用.reveal_type 始终可用,您无需导入.
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.
更多阅读:这里.
这篇关于如何在mypy中使用reveal_type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!