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 — Clarify error message for non `@runtime_checkable` decorated protocols by XuehaiPan · Pull Request #178 · python/typing_extensions

Conversation

@XuehaiPan

@XuehaiPan XuehaiPan commented May 23, 2023

Copy link
Copy Markdown
Contributor

Hi typing-extension team. typing-extension version 4.6.0 just came out. It has caused some of the CI failures on our side (https://github.com/metaopt/optree/actions/runs/5054617196/jobs/9069750456). We are going to fix this misusage as a bug on our side (as the new behavior will be the standard API in future Python releases). But I found the error message that was raised is not very clear.

typing_extensions/src/typing_extensions.py

Lines 703 to 704 in 356934c

raise TypeError("Instance and class checks can only be used with"
" @runtime protocols")

typing_extensions/src/typing_extensions.py

Lines 759 to 760 in 356934c

# Exists for backwards compatibility.
runtime = runtime_checkable

This PR changes deprecated @runtime to formal API @runtime_checkable in the error message.


The error in https://github.com/metaopt/optree/actions/runs/5054617196/jobs/9069750456 was raised by:

class MyProtocol(Protocol[T]):
    ...

class MyClass(MyProtocal[T]):
    ...

MyProtocal.register(MyClass)  # raises TypeError for `MyProtocol` is not `runtime_checkable`

Refs:

  • Backport some recent Protocol fixes from 3.12 #161
  • bpo-38908: Fix issue when non runtime_protocol does not raise TypeError cpython#26067
  • Backport CPython PR 26067 #132
  • Runtime-checkable protocol tests: Use @runtime_checkable, not @runtime #134
  • fix(typing): add @runtime_checkable decorator for CustomTreeNode protocol class metaopt/optree#56

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@XuehaiPan
Clarify error message for non @runtime_checkable decorated protocols
6b0faa7
@XuehaiPan XuehaiPan mentioned this pull request May 23, 2023
fix(typing): add @runtime_checkable decorator for CustomTreeNode protocol class metaopt/optree#56
Merged
8 of 12 tasks
AlexWaygood
AlexWaygood approved these changes May 23, 2023
View reviewed changes

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM! This matches the error message that CPython uses

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
srittau
srittau approved these changes May 23, 2023
View reviewed changes
srittau
srittau requested changes May 23, 2023
View reviewed changes

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Actually, could you add a CHANGELOG entry under a new # Unreleased header?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@XuehaiPan
Add CHANGLOG entry
7aa4518
srittau
srittau approved these changes May 23, 2023
View reviewed changes
@srittau
srittau merged commit b306e56 into python:main May 23, 2023
@XuehaiPan
XuehaiPan deleted the runtime-checkable-protocol branch May 23, 2023 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@srittau srittau srittau approved these changes
@AlexWaygood AlexWaygood AlexWaygood approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@XuehaiPan @srittau @AlexWaygood
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — 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.