如何在mypy中使用reveal_type

2024-09-28 17:21:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我读过,我可以通过使用一个名为reveal_type的函数来显示变量的类型,但是我找不到如何使用它或从何处导入它。在


Tags: 函数类型typereveal
1条回答
网友
1楼 · 发布于 2024-09-28 17:21:19

最后我发现了如何使用它:您应该在代码中放入并使用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。在

相关问题 更多 >