Typing and Generics
typing.reveal_type
Requests a static checker diagnostic reporting the inferred type. At runtime it prints the actual type name to stderr and returns the original object. Added in 3.11. Static and runtime types can differ.
Formal Syntax & Structure
python syntaxpython
typing.reveal_type(obj, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| obj | object | Object whose type is reported. |
Return Value
object
Typing construct or runtime result as described; static typing rules are not runtime validation.
Working Example
Example Snippetpython
from typing import reveal_type
import contextlib, iostream=io.StringIO()value=7with contextlib.redirect_stderr(stream): result=reveal_type(value)print((result,stream.getvalue().strip()))