Skip to content

Commit c286acd

Browse files
Update common_issues.rst: update information about reveal type and reveal locals
Previously it was impossible to have these in at run time (more or less), but now you can just import them.
1 parent 501a07b commit c286acd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

docs/source/common_issues.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,15 @@ to see the types of all local variables at once. Example:
505505
# b: builtins.str
506506
.. note::
507507

508-
``reveal_type`` and ``reveal_locals`` are only understood by mypy and
509-
don't exist in Python. If you try to run your program, you'll have to
510-
remove any ``reveal_type`` and ``reveal_locals`` calls before you can
511-
run your code. Both are always available and you don't need to import
512-
them.
508+
``reveal_type`` and ``reveal_locals`` are understood by mypy during typechecking,
509+
and don't have to be imported as functions. However,
510+
if you don't import them, then they don't exist at runtime! Therefore,
511+
in that case, if you try to run your program, you'll have to
512+
remove any ``reveal_type`` and ``reveal_locals`` calls
513+
or else Python will give you an error at runtime about those names being undefined.
514+
Alternatively, you can import ``reveal_type`` from ``typing_extensions`` (or, in more recent versions of python, from ``typing``) so its name will be defined at runtime.
515+
There is no analogous fix for ``reveal_locals``. It simply must be removed from the code before the code is run.
516+
(Although, technically, if you really didn't want to remove those calls, you could use ``if not TYPE_CHECKING: reveal_locals = lambda: pass`` or similar to define the function to something else at runtime.)
513517

514518
.. _silencing-linters:
515519

0 commit comments

Comments
 (0)