Skip to content
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

Clarify error message for non @runtime_checkable decorated protocols #178

Merged
merged 2 commits into from May 23, 2023

Conversation

XuehaiPan
Copy link
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.

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

# 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:

Copy link
Member

@AlexWaygood AlexWaygood left a 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

Copy link
Collaborator

@srittau srittau left a 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?

@srittau srittau merged commit b306e56 into python:main May 23, 2023
16 checks passed
@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants