GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add typing.reveal_type · Issue #90572 · python/cpython

Add typing.reveal_type #90572

New issue
Copy link
New issue
Copy link
Closed
Closed
Add typing.reveal_type#90572
Copy link
Assignees
JelleZijlstra
Labels
3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

Description

@JelleZijlstra
JelleZijlstra
opened on Jan 17, 2022
Issue body actions
BPO 46414
Nosy @gvanrossum, @srittau, @JelleZijlstra, @sobolevn, @Fidget-Spinner, @AlexWaygood, @cdce8p
PRs
  • bpo-46414: Add typing.reveal_type #30646
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/JelleZijlstra'
    closed_at = <Date 2022-03-05.17:53:23.394>
    created_at = <Date 2022-01-17.15:02:22.942>
    labels = ['library', '3.11']
    title = 'Add typing.reveal_type'
    updated_at = <Date 2022-03-05.17:53:23.394>
    user = 'https://github.com/JelleZijlstra'

    bugs.python.org fields:

    activity = <Date 2022-03-05.17:53:23.394>
    actor = 'JelleZijlstra'
    assignee = 'JelleZijlstra'
    closed = True
    closed_date = <Date 2022-03-05.17:53:23.394>
    closer = 'JelleZijlstra'
    components = ['Library (Lib)']
    creation = <Date 2022-01-17.15:02:22.942>
    creator = 'JelleZijlstra'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46414
    keywords = ['patch']
    message_count = 2.0
    messages = ['410794', '412333']
    nosy_count = 7.0
    nosy_names = ['gvanrossum', 'srittau', 'JelleZijlstra', 'sobolevn', 'kj', 'AlexWaygood', 'cdce8p']
    pr_nums = ['30646']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46414'
    versions = ['Python 3.11']

    Activity

    1. JelleZijlstra commented on Jan 17, 2022

      @JelleZijlstra
      JelleZijlstra
      on Jan 17, 2022
      MemberAuthor
      More actions

      The reveal_type() primitive is injected by type checkers into the builtins. When the type checker sees a call, it prints the inferred type of the argument.

      This has been implemented across all type checkers, but adding an implementation to typing would help document the behavior and make it more discoverable for users. Also, it means code with reveal_type() calls can run without runtime errors, useful if you want to run your tests at the same time as you're debugging a typing issue.

      The runtime implementation can be very simple:

          def reveal_type(obj: _T, /) -> _T:
              print("Runtime type is", type(obj))
              return obj

      reveal_type() is supported by all type checkers that I'm aware of (docs include https://google.github.io/pytype/faq.html#can-i-find-out-what-pytype-thinks-the-type-of-my-expression-is for pytype and https://mypy.readthedocs.io/en/stable/common_issues.html#reveal-type for mypy).

      One area of divergence is the return value. Pyright returns the inferred type of the expression as a string (and uses that in its test suite for testing type inference). Mypy returns the argument, which has the advantage that you can insert reveal_type() in the middle of an expression without having to put it on its own line. Also, the Pyright behavior cannot sensibly be implemented at runtime. Therefore, I suggest using Mypy's behavior for typing.reveal_type.

    2. JelleZijlstra
      added
      3.11only security fixesonly security fixes
      on Jan 17, 2022
    3. JelleZijlstra
      self-assigned this
      on Jan 17, 2022
    4. JelleZijlstra
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      3.11only security fixesonly security fixes
      on Jan 17, 2022
    5. JelleZijlstra
      self-assigned this
      on Jan 17, 2022
    6. JelleZijlstra
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on Jan 17, 2022
    7. gvanrossum commented on Feb 2, 2022

      @gvanrossum
      gvanrossum
      on Feb 2, 2022
      Member
      More actions

      New changeset abcc3d7 by Jelle Zijlstra in branch 'main':
      bpo-46414: Add typing.reveal_type (bpo-30646)
      abcc3d7

    8. JelleZijlstra
      closed this as completedon Mar 5, 2022
    9. JelleZijlstra
      closed this as completedon Mar 5, 2022
    10. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @JelleZijlstra
      JelleZijlstra

    Labels

    3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.