@@ -2581,33 +2581,32 @@ Functions and decorators
2581
2581
2582
2582
.. function :: reveal_type(obj, /)
2583
2583
2584
- Reveal the inferred static type of an expression.
2584
+ Ask a static type checker to reveal the inferred type of an expression.
2585
2585
2586
2586
When a static type checker encounters a call to this function,
2587
- it emits a diagnostic with the type of the argument. For example::
2587
+ it emits a diagnostic with the inferred type of the argument. For example::
2588
2588
2589
2589
x: int = 1
2590
2590
reveal_type(x) # Revealed type is "builtins.int"
2591
2591
2592
2592
This can be useful when you want to debug how your type checker
2593
2593
handles a particular piece of code.
2594
2594
2595
- The function returns its argument unchanged, which allows using
2596
- it within an expression::
2595
+ At runtime, this function prints the runtime type of its argument to
2596
+ :data: `sys.stderr ` and returns the argument unchanged (allowing the call to
2597
+ be used within an expression)::
2597
2598
2598
- x = reveal_type(1) # Revealed type is "builtins.int"
2599
+ x = reveal_type(1) # prints "Runtime type is int"
2600
+ print(x) # prints "1"
2601
+
2602
+ Note that the runtime type may be different from (more or less specific
2603
+ than) the type statically inferred by a type checker.
2599
2604
2600
2605
Most type checkers support ``reveal_type() `` anywhere, even if the
2601
2606
name is not imported from ``typing ``. Importing the name from
2602
- ``typing `` allows your code to run without runtime errors and
2607
+ ``typing ``, however, allows your code to run without runtime errors and
2603
2608
communicates intent more clearly.
2604
2609
2605
- At runtime, this function prints the runtime type of its argument to stderr
2606
- and returns it unchanged::
2607
-
2608
- x = reveal_type(1) # prints "Runtime type is int"
2609
- print(x) # prints "1"
2610
-
2611
2610
.. versionadded :: 3.11
2612
2611
2613
2612
.. decorator :: dataclass_transform(*, eq_default=True, order_default=False, \
0 commit comments