How to use reveal_type in mypy

限于喜欢 提交于 2020-12-25 01:36:43

问题


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.


回答1:


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*'

From the mypy documentation:

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.

For more reading: here.



来源:https://stackoverflow.com/questions/44625422/how-to-use-reveal-type-in-mypy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!