Skip to content

bpo-46414: Add typing.reveal_type #30646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test the stdout and make it nicer
  • Loading branch information
JelleZijlstra committed Jan 22, 2022
commit 742884a00706739773d77eedacee64d52c802bc1
6 changes: 4 additions & 2 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import weakref
import types

from test.support import import_helper
from test.support import import_helper, captured_stdout
from test import mod_generics_cache
from test import _typed_dict_helper

Expand Down Expand Up @@ -5112,7 +5112,9 @@ def bar(self):
class RevealTypeTests(BaseTestCase):
def test_reveal_type(self):
obj = object()
self.assertIs(obj, reveal_type(obj))
with captured_stdout() as stdout:
self.assertIs(obj, reveal_type(obj))
self.assertEqual(stdout.getvalue(), "Runtime type is 'object'\n")


class AllTests(BaseTestCase):
Expand Down
2 changes: 1 addition & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2686,5 +2686,5 @@ def reveal_type(obj: T, /) -> T:
argument and returns it unchanged.

"""
print("Runtime type is", type(obj))
print(f"Runtime type is {type(obj).__name__!r}")
return obj