Python Glossary Русский

Python 3.11+typingfunction

typing.reveal_type

casting and debugging

A debugging helper; the type checker prints the inferred type. At runtime returns the argument (3.11+).

Syntax

typing.reveal_type(value)

This is a checker-time probe, not a runtime feature: mypy or pyright print the inferred type and usually flag the line so you won't leave it behind. At runtime it merely returns its argument and writes the type to stderr, so strip it out once you've finished debugging your annotations.

Examples

from typing import reveal_type
print(reveal_type(42))                    # → 42
print(reveal_type('hi').upper())          # → HI
print(reveal_type([1, 2]) == [1, 2])      # → True
print(type(reveal_type(3.5)).__name__)    # → float
print(callable(reveal_type))              # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy