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 — Backport CPython PR 26067 by AlexWaygood · Pull Request #132 · python/typing_extensions

Conversation

@AlexWaygood

@AlexWaygood AlexWaygood commented Apr 9, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

This backports the CPython PR python/cpython#26067, which was backported to Python 3.10 but no earlier in the CPython repo.

(It was initially backported to 3.9, but the backport was reverted: python/cpython#26077.)

Since we're now backporting a bugfix to <=3.9, this means that we re-implement Protocol/runtime_checkable on <=3.9, rather than on just 3.7. Doing this requires a change to _get_protocol_attrs; I also tweaked typing_extensions.runtime_checkable so that it also works on typing.Protocol, if typing.Protocol exists.

Sorry, something went wrong.

Uh oh!

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

All reactions
AlexWaygood and others added 6 commits April 9, 2023 22:20
@AlexWaygood
Backport CPython PR 26067
587d843
@AlexWaygood
See if this fixes things
8ab4bdb
@AlexWaygood
oops
afbafbb
@AlexWaygood
.
376e9c2
@AlexWaygood
Merge branch 'main' into backport-26067
53155cd
@AlexWaygood
.
64f059b
@AlexWaygood
AlexWaygood marked this pull request as draft April 9, 2023 21:34
@AlexWaygood
.
30f4c83
@AlexWaygood

AlexWaygood commented Apr 9, 2023

Copy link
Copy Markdown
Member Author

Not sure why that test is failing only on 3.9; it's a bit weird. I'll try to take another look tomorrow, but any suggestions are welcome :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@AlexWaygood
Fix tests on 3.9
b507d3c
@AlexWaygood
AlexWaygood marked this pull request as ready for review April 10, 2023 12:16
@AlexWaygood

AlexWaygood commented Apr 10, 2023

Copy link
Copy Markdown
Member Author

Not sure why that test is failing only on 3.9; it's a bit weird.

I figured it out -- __class_getitem__ was being counted as a protocol member on Python 3.9. All green now!

All reactions

Sorry, something went wrong.

Uh oh!

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

AlexWaygood added 3 commits April 11, 2023 15:56
@AlexWaygood
Allow typing_extensions.runtime_checkable to decorate typing.Protocol
f77322c
@AlexWaygood
Fix flake8 errors
982efce
@AlexWaygood
Merge remote-tracking branch 'upstream/main' into backport-26067
be9940d
@srittau

srittau commented Apr 12, 2023

Copy link
Copy Markdown
Collaborator

Sorry for being a pain, but could we split out the flake8 changes for a cleaner history?

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@AlexWaygood AlexWaygood mentioned this pull request Apr 12, 2023
flake8 config: ignore W503 #135
Merged
@AlexWaygood

AlexWaygood commented Apr 12, 2023

Copy link
Copy Markdown
Member Author

Sorry for being a pain, but could we split out the flake8 changes for a cleaner history?

  • flake8 config: ignore W503 #135
All reactions

Sorry, something went wrong.

Uh oh!

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

@AlexWaygood
Merge branch 'main' into backport-26067
ee378c7
srittau
srittau approved these changes Apr 12, 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.

My understanding of typing internals is limited, but this LGTM, apart from the comment about flake8 and a question below.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread src/typing_extensions.py
return NotImplemented
if not getattr(cls, '_is_runtime_protocol', False):
if _caller(depth=3) in {'abc', 'functools'}:
if _allow_reckless_class_checks():

@srittau srittau Apr 12, 2023

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.

Is it correct that the depth is changed from 3 to 4?

Sorry, something went wrong.

Uh oh!

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

All reactions

@AlexWaygood AlexWaygood Apr 12, 2023

Copy link
Copy Markdown
Member Author

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.

Yes, because by adding a new function that the code has to pass through before it gets to the sys._getframe call, the call stack becomes "another frame deep"

Sorry, something went wrong.

Uh oh!

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

srittau reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@srittau srittau Apr 12, 2023

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.

I could just have looked at _caller and figured that out myself. 🤦

Sorry, something went wrong.

Uh oh!

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

AlexWaygood reacted with laugh emoji
All reactions
  • 😄 1 reaction
Comment thread src/typing_extensions.py
" @runtime protocols")
if not _is_callable_members_only(cls):
if _caller(depth=3) in {'abc', 'functools'}:
if _allow_reckless_class_checks():

@srittau srittau Apr 12, 2023

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.

Here as well?

Sorry, something went wrong.

Uh oh!

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

All reactions

@AlexWaygood AlexWaygood Apr 12, 2023

Copy link
Copy Markdown
Member Author

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.

Same as above

Sorry, something went wrong.

Uh oh!

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

All reactions
@srittau
srittau merged commit 7e998c2 into python:main Apr 12, 2023
@AlexWaygood
AlexWaygood deleted the backport-26067 branch April 12, 2023 08:45
@AlexWaygood

AlexWaygood commented Apr 12, 2023

Copy link
Copy Markdown
Member Author

Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

@AlexWaygood AlexWaygood mentioned this pull request May 21, 2023
Add documentation page for typing-extensions #166
Merged
This was referenced May 23, 2023
Clarify error message for non @runtime_checkable decorated protocols #178
Merged
fix(typing): add @runtime_checkable decorator for CustomTreeNode protocol class metaopt/optree#56
Merged
@serena-ruan serena-ruan mentioned this pull request May 23, 2023
fix failing space & langchain tests mlflow/mlflow#8513
Merged
2 of 33 tasks
This was referenced May 25, 2023
TypeError: Instance and class checks can only be used with @runtime_checkable protocols #187
Closed
runtime_checkable error in newer versions caused by a protocol subclass #207
Closed
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

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.

2 participants

@AlexWaygood @srittau
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.