From c286acdd056f6d1080e494abbf27beb2fb9e1410 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Thu, 8 May 2025 15:30:57 -0700 Subject: [PATCH 01/10] 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. --- docs/source/common_issues.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 96d73e5f03992..f49b435f9c2ef 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -505,11 +505,15 @@ to see the types of all local variables at once. Example: # b: builtins.str .. note:: - ``reveal_type`` and ``reveal_locals`` are only understood by mypy and - don't exist in Python. If you try to run your program, you'll have to - remove any ``reveal_type`` and ``reveal_locals`` calls before you can - run your code. Both are always available and you don't need to import - them. + ``reveal_type`` and ``reveal_locals`` are understood by mypy during typechecking, + and don't have to be imported as functions. However, + if you don't import them, then they don't exist at runtime! Therefore, + in that case, if you try to run your program, you'll have to + remove any ``reveal_type`` and ``reveal_locals`` calls + or else Python will give you an error at runtime about those names being undefined. + 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. + There is no analogous fix for ``reveal_locals``. It simply must be removed from the code before the code is run. + (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.) .. _silencing-linters: From 12dfc9c75219aa2c10181993cfd0a9bef95b67c7 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Thu, 8 May 2025 19:43:35 -0400 Subject: [PATCH 02/10] Update common_issues.rst: fix formatting, code example --- docs/source/common_issues.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index f49b435f9c2ef..6f62c196b6855 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -511,9 +511,9 @@ to see the types of all local variables at once. Example: in that case, if you try to run your program, you'll have to remove any ``reveal_type`` and ``reveal_locals`` calls or else Python will give you an error at runtime about those names being undefined. - 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. + 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. There is no analogous fix for ``reveal_locals``. It simply must be removed from the code before the code is run. - (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.) + (Although, technically, if you really didn't want to remove those calls, you could use ``if not TYPE_CHECKING: reveal_locals = lambda: None`` or similar to define the function to something else at runtime.) .. _silencing-linters: From f1855ecb2eea9d5c4bc850da84f13d2b27d83680 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Thu, 8 May 2025 21:27:47 -0400 Subject: [PATCH 03/10] Update common_issues.rst: finish formatting and improving the text --- docs/source/common_issues.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 6f62c196b6855..0dc484d78aba9 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -508,12 +508,14 @@ to see the types of all local variables at once. Example: ``reveal_type`` and ``reveal_locals`` are understood by mypy during typechecking, and don't have to be imported as functions. However, if you don't import them, then they don't exist at runtime! Therefore, - in that case, if you try to run your program, you'll have to - remove any ``reveal_type`` and ``reveal_locals`` calls + you'll have to remove any ``reveal_type`` and ``reveal_locals`` calls from your program or else Python will give you an error at runtime about those names being undefined. - 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. + Alternatively, you can import ``reveal_type`` from :py:data:`typing_extensions` + (or, in more recent versions of python, from :py:data:`typing`) so its name will be defined at runtime. There is no analogous fix for ``reveal_locals``. It simply must be removed from the code before the code is run. - (Although, technically, if you really didn't want to remove those calls, you could use ``if not TYPE_CHECKING: reveal_locals = lambda: None`` or similar to define the function to something else at runtime.) + (Although, technically, if you really didn't want to remove those calls, you could use + ``if not typing.TYPE_CHECKING: reveal_locals = lambda: None`` + or similar to define the function to something else at runtime.) .. _silencing-linters: From add993116bcd011db1cfa4af52af1bfcaeb5c0fc Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Thu, 8 May 2025 22:09:08 -0400 Subject: [PATCH 04/10] Update common_issues.rst: I guess you can't use py:data like that --- docs/source/common_issues.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 0dc484d78aba9..201b4966caaa3 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -510,9 +510,11 @@ to see the types of all local variables at once. Example: if you don't import them, then they don't exist at runtime! Therefore, you'll have to remove any ``reveal_type`` and ``reveal_locals`` calls from your program or else Python will give you an error at runtime about those names being undefined. - Alternatively, you can import ``reveal_type`` from :py:data:`typing_extensions` - (or, in more recent versions of python, from :py:data:`typing`) so its name will be defined at runtime. - There is no analogous fix for ``reveal_locals``. It simply must be removed from the code before the code is run. + 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. + There is no analogous fix for ``reveal_locals``. + It simply must be removed from the code before the code is run. (Although, technically, if you really didn't want to remove those calls, you could use ``if not typing.TYPE_CHECKING: reveal_locals = lambda: None`` or similar to define the function to something else at runtime.) From a85210691b510ebcd1d337d3f30a026f83b893e9 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Fri, 9 May 2025 03:34:13 -0700 Subject: [PATCH 05/10] intersphinx typing.reveal in case it starts working later it doesn't in my local testing, but that's ok because it gracefully degrades down to `normal code` --- docs/source/common_issues.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 201b4966caaa3..9e513a144c9b5 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -510,7 +510,7 @@ to see the types of all local variables at once. Example: if you don't import them, then they don't exist at runtime! Therefore, you'll have to remove any ``reveal_type`` and ``reveal_locals`` calls from your program or else Python will give you an error at runtime about those names being undefined. - Alternatively, you can import ``reveal_type`` from ``typing_extensions`` + Alternatively, you can import :py:data:`~typing.reveal_type` from ``typing_extensions`` (or, in more recent versions of python, from ``typing``) so its name will be defined at runtime. There is no analogous fix for ``reveal_locals``. From 1ea84e4224bd6064c2d8204fce2bfb51798f932b Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Fri, 9 May 2025 03:37:38 -0700 Subject: [PATCH 06/10] Revert "intersphinx typing.reveal in case it starts working later" Ah, nevermind: I actually get a hard error when I try to push that: `py:data reference target not found: typing.reveal_type`. This reverts commit a85210691b510ebcd1d337d3f30a026f83b893e9. --- docs/source/common_issues.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 9e513a144c9b5..201b4966caaa3 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -510,7 +510,7 @@ to see the types of all local variables at once. Example: if you don't import them, then they don't exist at runtime! Therefore, you'll have to remove any ``reveal_type`` and ``reveal_locals`` calls from your program or else Python will give you an error at runtime about those names being undefined. - Alternatively, you can import :py:data:`~typing.reveal_type` from ``typing_extensions`` + 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. There is no analogous fix for ``reveal_locals``. From a118a89f21ac31669dc6e86c52fd8d406442c816 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Sun, 11 May 2025 08:33:30 -0700 Subject: [PATCH 07/10] you know what, maybe I will unragged the right --- docs/source/common_issues.rst | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 201b4966caaa3..4293c1cbf2ab9 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -504,20 +504,19 @@ to see the types of all local variables at once. Example: # a: builtins.int # b: builtins.str .. note:: - - ``reveal_type`` and ``reveal_locals`` are understood by mypy during typechecking, - and don't have to be imported as functions. However, + ``reveal_type`` and ``reveal_locals`` are understood by mypy during + typechecking, and don't have to be imported as functions. However, if you don't import them, then they don't exist at runtime! Therefore, - you'll have to remove any ``reveal_type`` and ``reveal_locals`` calls from your program - or else Python will give you an error at runtime about those names being undefined. - 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. - There is no analogous fix for ``reveal_locals``. - It simply must be removed from the code before the code is run. - (Although, technically, if you really didn't want to remove those calls, you could use - ``if not typing.TYPE_CHECKING: reveal_locals = lambda: None`` - or similar to define the function to something else at runtime.) + you'll have to remove any ``reveal_type`` and ``reveal_locals`` calls + from your program or else Python will give you an error at runtime about + those names being undefined. 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. There is no analogous + fix for ``reveal_locals``. It simply must be removed from the code before + the code is run. (Although, technically, if you really didn't want to + remove those calls, you could use ``if not typing.TYPE_CHECKING: + reveal_locals = lambda: None`` or similar to define the function to + something else at runtime.) .. _silencing-linters: From 559a8ebed51127823744b9297c260e7c58871cf9 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Tue, 13 May 2025 03:58:38 -0700 Subject: [PATCH 08/10] mention typing before typing_extensions --- docs/source/common_issues.rst | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 4293c1cbf2ab9..1eeda2c78c05e 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -504,19 +504,19 @@ to see the types of all local variables at once. Example: # a: builtins.int # b: builtins.str .. note:: - ``reveal_type`` and ``reveal_locals`` are understood by mypy during - typechecking, and don't have to be imported as functions. However, - if you don't import them, then they don't exist at runtime! Therefore, - you'll have to remove any ``reveal_type`` and ``reveal_locals`` calls - from your program or else Python will give you an error at runtime about - those names being undefined. 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. There is no analogous - fix for ``reveal_locals``. It simply must be removed from the code before - the code is run. (Although, technically, if you really didn't want to - remove those calls, you could use ``if not typing.TYPE_CHECKING: - reveal_locals = lambda: None`` or similar to define the function to - something else at runtime.) + + ``reveal_type`` and ``reveal_locals`` are understood by mypy during + typechecking, and don't have to be imported as functions. However, if you + don't import them, then they don't exist at runtime! Therefore, you'll have + to remove any ``reveal_type`` and ``reveal_locals`` calls from your program + or else Python will give you an error at runtime about those names being + undefined. Alternatively, you can import ``reveal_type`` from ``typing`` + (or, in versions of python older than 3.11, from ``typing_extensions``) so + its name will be defined at runtime. There is no analogous fix for + ``reveal_locals``. It simply must be removed from the code before the code + is run. (Although, technically, if you really didn't want to remove those + calls, you could use ``if not typing.TYPE_CHECKING: reveal_locals = lambda: + None`` or similar to define the function to something else at runtime.) .. _silencing-linters: From 1879edf0ad400c52709a08c4a8c2f59c2dddf073 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 2 Aug 2025 15:08:54 -0700 Subject: [PATCH 09/10] Update docs/source/common_issues.rst --- docs/source/common_issues.rst | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index 1eeda2c78c05e..c442c0c481631 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -505,18 +505,15 @@ to see the types of all local variables at once. Example: # b: builtins.str .. note:: - ``reveal_type`` and ``reveal_locals`` are understood by mypy during - typechecking, and don't have to be imported as functions. However, if you - don't import them, then they don't exist at runtime! Therefore, you'll have - to remove any ``reveal_type`` and ``reveal_locals`` calls from your program - or else Python will give you an error at runtime about those names being - undefined. Alternatively, you can import ``reveal_type`` from ``typing`` - (or, in versions of python older than 3.11, from ``typing_extensions``) so - its name will be defined at runtime. There is no analogous fix for - ``reveal_locals``. It simply must be removed from the code before the code - is run. (Although, technically, if you really didn't want to remove those - calls, you could use ``if not typing.TYPE_CHECKING: reveal_locals = lambda: - None`` or similar to define the function to something else at runtime.) + ``reveal_type`` and ``reveal_locals`` are handled specially by mypy during + type checking, and don't have to be defined or imported. + + However, if you want to run your code, + you'll have to remove any ``reveal_type`` and ``reveal_locals`` + calls from your program or else Python will give you an error at runtime. + + Alternatively, you can import ``reveal_type`` from ``typing_extensions`` + or ``typing`` (on Python 3.11 and newer) .. _silencing-linters: From c357564d0d72b1b96c268a83166e1584f918d62f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 2 Aug 2025 22:10:12 +0000 Subject: [PATCH 10/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/common_issues.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/common_issues.rst b/docs/source/common_issues.rst index c442c0c481631..a870c52c53d2a 100644 --- a/docs/source/common_issues.rst +++ b/docs/source/common_issues.rst @@ -507,11 +507,11 @@ to see the types of all local variables at once. Example: ``reveal_type`` and ``reveal_locals`` are handled specially by mypy during type checking, and don't have to be defined or imported. - + However, if you want to run your code, you'll have to remove any ``reveal_type`` and ``reveal_locals`` calls from your program or else Python will give you an error at runtime. - + Alternatively, you can import ``reveal_type`` from ``typing_extensions`` or ``typing`` (on Python 3.11 and newer)