Skip to content

gh-113255: Clarify docs for typing.reveal_type #113286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 20, 2023
10 changes: 7 additions & 3 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2604,10 +2604,11 @@ Functions and decorators

.. function:: reveal_type(obj, /)

Reveal the inferred static type of an expression.
Ask a static type checker to reveal the statically inferred type of an
expression.

When a static type checker encounters a call to this function,
it emits a diagnostic with the type of the argument. For example::
When a static type checker encounters a call to this function, it emits a
diagnostic with the inferred static type of the argument. For example::

x: int = 1
reveal_type(x) # Revealed type is "builtins.int"
Expand All @@ -2631,6 +2632,9 @@ Functions and decorators
x = reveal_type(1) # prints "Runtime type is int"
print(x) # prints "1"

Note that the runtime type may be different from (more or less specific
than) the type statically inferred by a type checker.

.. versionadded:: 3.11

.. decorator:: dataclass_transform(*, eq_default=True, order_default=False, \
Expand Down