如何在mypy中使用reveal_type
How to use reveal_type in 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.
我读到我可以通过使用一个名为 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.