Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reveal type hints in PyCharm?

Python's mypy has a special function called reveal_type() which asks the linter to display the type of variables.

PyCharm does not support it and instead shows the function as non-existing.

How can I display the type hint of a variable?

like image 623
Bharel Avatar asked Oct 25 '25 03:10

Bharel


2 Answers

By default, PyCharm binds the F1 key to the "display documentation" command.

PyCharm example screenshot

When displaying the documentation, you're able to see the type of variables, function signatures, class signatures, and docstrings.

You're also able to view the type directly using ctrl+shift+P or by hovering with the mouse and pressing ctrl.

If you do not use the default keymap, you may navigate to View | Quick documentation:

enter image description here

like image 142
Bharel Avatar answered Oct 27 '25 18:10

Bharel


Starting 2025.2, PyCharm will show inlay hints next to reveal_type() calls:

a = [0] + ['']; reveal_type(a); list[str | int]

like image 27
InSync Avatar answered Oct 27 '25 16:10

InSync