How to use reveal_type in mypy

后端 未结 1 1235
星月不相逢
星月不相逢 2021-01-03 20:35

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条回答
  • 2021-01-03 20:38

    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.

    0 讨论(0)
提交回复
热议问题