@@ -2323,33 +2323,32 @@ Functions and decorators
2323
2323
2324
2324
.. function :: reveal_type(obj, /)
2325
2325
2326
- Reveal the inferred static type of an expression.
2326
+ Ask a static type checker to reveal the inferred type of an expression.
2327
2327
2328
2328
When a static type checker encounters a call to this function,
2329
- it emits a diagnostic with the type of the argument. For example::
2329
+ it emits a diagnostic with the inferred type of the argument. For example::
2330
2330
2331
2331
x: int = 1
2332
2332
reveal_type(x) # Revealed type is "builtins.int"
2333
2333
2334
2334
This can be useful when you want to debug how your type checker
2335
2335
handles a particular piece of code.
2336
2336
2337
- The function returns its argument unchanged, which allows using
2338
- it within an expression::
2337
+ At runtime, this function prints the runtime type of its argument to
2338
+ :data: `sys.stderr ` and returns the argument unchanged (allowing the call to
2339
+ be used within an expression)::
2339
2340
2340
- x = reveal_type(1) # Revealed type is "builtins.int"
2341
+ x = reveal_type(1) # prints "Runtime type is int"
2342
+ print(x) # prints "1"
2343
+
2344
+ Note that the runtime type may be different from (more or less specific
2345
+ than) the type statically inferred by a type checker.
2341
2346
2342
2347
Most type checkers support ``reveal_type() `` anywhere, even if the
2343
2348
name is not imported from ``typing ``. Importing the name from
2344
- ``typing `` allows your code to run without runtime errors and
2349
+ ``typing ``, however, allows your code to run without runtime errors and
2345
2350
communicates intent more clearly.
2346
2351
2347
- At runtime, this function prints the runtime type of its argument to stderr
2348
- and returns it unchanged::
2349
-
2350
- x = reveal_type(1) # prints "Runtime type is int"
2351
- print(x) # prints "1"
2352
-
2353
2352
.. versionadded :: 3.11
2354
2353
2355
2354
.. decorator :: dataclass_transform(*, eq_default=True, order_default=False, \
0 commit comments