FWIW, my objection to adding these to stdlib stands. On Sat, 2022-01-22 at 14:32 -0800, Jelle Zijlstra wrote:
In the previous thread about reveal_type(), several people proposed also adding `typing.reveal_locals()`. In this thread I'd like to iron out any details and make sure we're all in agreement.
# Specification
We will add a new function `typing.reveal_locals()` with the following signature:
def reveal_locals() -> None: ...
At runtime, this function will do nothing.
When a type checker encounters a call to reveal_locals(), it will emit the types of all variables in the local scope. For example:
def f() -> None: a = 1 b = "x" reveal_locals()
When typechecked, this may produce:
Revealed local types are: a: builtins.int b: builtins.str
# Motivation
`reveal_locals()` is already implemented in mypy ( https://mypy.readthedocs.io/en/stable/common_issues.html#displaying-the-type... ) and pyright (undocumented). It is not as commonly used as reveal_type(), but can be useful for debugging type checker behavior.
# Open questions
What should the runtime behavior be? We could do something like sys._getframe(1).f_locals to get the calling function's locals and print them, but that isn't code I'd like to write.
_______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: pbryan@anode.ca