-
-
Notifications
You must be signed in to change notification settings - Fork 35k
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
Changes from 1 commit
a4d99ef
e24a8a2
8f5f750
742884a
e447293
b2bbe06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Part of the documentation was taken from mypy: https://mypy.readthedocs.io/en/stable/common_issues.html#reveal-type
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -130,6 +130,7 @@ def _idfunc(_, x): | |||
| 'overload', | ||||
| 'ParamSpecArgs', | ||||
| 'ParamSpecKwargs', | ||||
| 'reveal_type', | ||||
| 'runtime_checkable', | ||||
| 'Text', | ||||
| 'TYPE_CHECKING', | ||||
|
|
@@ -2667,3 +2668,23 @@ class re(metaclass=_DeprecatedType): | |||
|
|
||||
| re.__name__ = __name__ + '.re' | ||||
| sys.modules[re.__name__] = re | ||||
|
|
||||
|
|
||||
| def reveal_type(obj: T, /) -> T: | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we use type hints in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is merged, we will :). I don't see any reason not to, especially in cases like this where the type is simple and helps document the behavior.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are type annotations in a few lines of Line 2531 in 270a091
It's just about the only module in the stdlib in which I've spotted any type annotations other than importlib :) |
||||
| """Reveal the inferred type of a variable. | ||||
|
|
||||
| When a static type checker encounters a call to ``reveal_type()``, | ||||
| it will emit the inferred type of the argument:: | ||||
|
|
||||
| x: int = 1 | ||||
| reveal_type(x) | ||||
|
|
||||
| Running a static type checker (e.g., ``mypy``) on this example | ||||
| will produce output similar to 'Revealed type is "builtins.int"'. | ||||
|
|
||||
| At runtime, the function prints the runtime type of the | ||||
| argument and returns it unchanged. | ||||
|
|
||||
| """ | ||||
| print("Runtime type is", type(obj)) | ||||
| return obj | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add ``typing.reveal_type()``. Patch by Jelle Zijlstra. | ||
|
JelleZijlstra marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.