@@ -2604,33 +2604,32 @@ Functions and decorators
2604
2604
2605
2605
.. function :: reveal_type(obj, /)
2606
2606
2607
- Reveal the inferred static type of an expression.
2607
+ Ask a static type checker to reveal the inferred type of an expression.
2608
2608
2609
2609
When a static type checker encounters a call to this function,
2610
- it emits a diagnostic with the type of the argument. For example::
2610
+ it emits a diagnostic with the inferred type of the argument. For example::
2611
2611
2612
2612
x: int = 1
2613
2613
reveal_type(x) # Revealed type is "builtins.int"
2614
2614
2615
2615
This can be useful when you want to debug how your type checker
2616
2616
handles a particular piece of code.
2617
2617
2618
- The function returns its argument unchanged, which allows using
2619
- it within an expression::
2618
+ At runtime, this function prints the runtime type of its argument to
2619
+ :data: `sys.stderr ` and returns the argument unchanged (allowing the call to
2620
+ be used within an expression)::
2620
2621
2621
- x = reveal_type(1) # Revealed type is "builtins.int"
2622
+ x = reveal_type(1) # prints "Runtime type is int"
2623
+ print(x) # prints "1"
2624
+
2625
+ Note that the runtime type may be different from (more or less specific
2626
+ than) the type statically inferred by a type checker.
2622
2627
2623
2628
Most type checkers support ``reveal_type() `` anywhere, even if the
2624
2629
name is not imported from ``typing ``. Importing the name from
2625
- ``typing `` allows your code to run without runtime errors and
2630
+ ``typing ``, however, allows your code to run without runtime errors and
2626
2631
communicates intent more clearly.
2627
2632
2628
- At runtime, this function prints the runtime type of its argument to stderr
2629
- and returns it unchanged::
2630
-
2631
- x = reveal_type(1) # prints "Runtime type is int"
2632
- print(x) # prints "1"
2633
-
2634
2633
.. versionadded :: 3.11
2635
2634
2636
2635
.. decorator :: dataclass_transform(*, eq_default=True, order_default=False, \
0 commit comments