Backport performance improvements to runtime-checkable protocols by AlexWaygood · Pull Request #137 · python/typing_extensions · GitHub

github.com

Tin mới

AlexWaygood:improve-protocol-perf

GitHub CopilotWrite better code with AI

GitHub Copilot appDirect agents from issue to merge

ActionsAutomate any workflow

CodespacesInstant dev environments

IssuesPlan and track work

Code ReviewManage code changes

Code QualityEnforce quality at merge

GitHub Advanced SecurityFind and fix vulnerabilities

Code securitySecure your code as you build

Secret protectionStop leaks before they start

View all use cases

Financial services

View all industries

Software Development

GitHub SponsorsFund open source developers

Copilot for BusinessEnterprise-grade AI features

Premium SupportEnterprise-grade 24/7 support

Security and quality 0

gh-74690: typing: Don't unnecessarily call _get_protocol_attrs twice in _ProtocolMeta.__instancecheck__ cpython#103141

gh-74690: Micro-optimise typing._get_protocol_attrs cpython#103152

gh-74690: typing: Simplify and optimise _ProtocolMeta.__instancecheck__ cpython#103159

gh-74690: typing: Call _get_protocol_attrs and _callable_members_only at protocol class creation time, not during isinstance() checks cpython#103160

gh-74690: Further optimise typing._ProtocolMeta.__instancecheck__ cpython#103280

python/cpython#103034

This PR backports the following CPython PRs (all by me), which, taken together, substantially improve the performance of isinstance() checks against runtime-checkable protocols on Python 3.12 compared to Python 3.11:

Backport several performance improvements for runtime-checkable proto…

Fix tests on Python 3.11

View reviewed changes

Learn more about hiding disruptive comments

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

Merge branch 'main' into improve-protocol-perf

Remove flake8-noqa from test-requirements.txt #138

View reviewed changes

dgilland/pydash#197

This change seems to have broken the latest version of pydash when used with typing-extensions 4.6.0. There's a bug report about this here: dgilland/pydash#197.

https://github.com/dgilland/pydash/blob/051fe69c3e523f903a0a0ea6ca6a5c2d4b83a3e7/src/pydash/utilities.py#L577-L638

This change seems to have broken the latest version of pydash when used with typing-extensions 4.6.0. There's a bug report about this here: dgilland/pydash#197.

Cannot parameterise typing_extensions.Protocol with a ParamSpec or TypeVarTuple on py310+ #181