FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-46414: Add typing.reveal_type by JelleZijlstra · Pull Request #30646 · python/cpython · GitHub

/ cpython Public

bpo-46414: Add typing.reveal_type - #30646

Merged
gvanrossum merged 6 commits into
python:mainfrom
JelleZijlstra:revealtype
Feb 2, 2022
Merged

bpo-46414: Add typing.reveal_type#30646
gvanrossum merged 6 commits into
python:mainfrom
JelleZijlstra:revealtype

Conversation

JelleZijlstra commented Jan 17, 2022
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

Comment thread Doc/library/typing.rst Outdated
Comment thread Lib/test/test_typing.py Outdated

Copy link
Copy Markdown
Member

Thank you! This solves my old pain with redefining reveal_type as:

from typing import TYPE_CHECKING
if not TYPE_CHECKING:
    reveal_type = print

Copy link
Copy Markdown
Member

Hold on. This feels awkward, since previously this was a builtin. I don’t want to have to import it.

Copy link
Copy Markdown
Member Author

Hold on. This feels awkward, since previously this was a builtin. I don’t want to have to import it.

Type checkers would still allow using it without the import. You'll have the option to import it if you want to run your code or document to readers what reveal_type() means.

Copy link
Copy Markdown
Member

It needs more discussion. Please wait until I have a keyboard.

Copy link
Copy Markdown
Member Author

No hurry! I also opened a thread on typing-sig about this, that's probably the best place to discuss how it should work.

Copy link
Copy Markdown
Member Author

@gvanrossum based on the discussion on typing-sig, are you satisfied with this change now?

I'm planning to also add reveal_locals() in a separate PR.

Copy link
Copy Markdown
Member Author

Wait, I didn't address Nikita's review yet.

Copy link
Copy Markdown
Member

Did we bikeshed yet whether it should write to stdout or stderr?

Copy link
Copy Markdown
Member Author

Did we bikeshed yet whether it should write to stdout or stderr?

No, though there have been some suggestions about the output format; I just sent a typing-sig email about that too. Personally I don't care much but I'd like to keep it simple.

Copy link
Copy Markdown
Member

Did we bikeshed yet whether it should write to stdout or stderr?

No, though there have been some suggestions about the output format; I just sent a typing-sig email about that too. Personally I don't care much but I'd like to keep it simple.

I'm just thinking that sending the output to stderr would be more in line with the debug nature of the API.

Copy link
Copy Markdown
Member Author

Pushed a change to make it write to stderr instead.

Comment thread Doc/library/typing.rst Outdated
Co-authored-by: Guido van Rossum <guido@python.org>
Comment thread Lib/typing.py
sys.modules[re.__name__] = re


def reveal_type(obj: T, /) -> T:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Do we use type hints in typing.py? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

AlexWaygood Jan 23, 2022
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There are type annotations in a few lines of typing.py:

def read(self, n: int = -1) -> AnyStr:

It's just about the only module in the stdlib in which I've spotted any type annotations other than importlib :)

Copy link
Copy Markdown
Member Author

@gvanrossum do you think this is ready to merge now? The discussion on typing-sig has died down. (You added the "Do not merge" label a while ago.)

I think the other new function PRs are also ready, but I can ping you on those later.

gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM.

gvanrossum merged commit abcc3d7 into python:main Feb 2, 2022

Copy link
Copy Markdown

@gvanrossum: Please replace # with GH- in the commit message next time. Thanks!

Copy link
Copy Markdown
Member

Should probably post the resolution to typing-sig.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL