gh-74690: typing: Don't unnecessarily call `_get_protocol_attrs` twice in `_ProtocolMeta.__instancecheck__` by AlexWaygood · Pull Request #103141 · python/cpython · GitHub

github.com

Tin mới

AlexWaygood:protocol-attrs-collection

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

Pull requests 2.6k

Security and quality 0

Performance of typing._ProtocolMeta._get_protocol_attrs and isinstance #74690

: typing: Don't unnecessarily call `_get_protocol_attrs…

awaiting core review

View reviewed changes

View reviewed changes

Learn more about hiding disruptive comments

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

caching mechanism for __instancecheck__ results

We could possibly cache the result of this call on the protocol class in a __protocol_attrs__ class attribute. ...

Delete 2023-03-30-23-51-22.gh-issue-74690.p2c4Co.rst

Merge branch 'main' into protocol-attrs-collection

View reviewed changes

Speaking from experience?

I've found users often depend on undocumented aspects of typing.py

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

gh-102433: Use inspect.getattr_static in typing._ProtocolMeta.__instancecheck__ #103034

gh-74690: Document changes made to runtime-checkable protocols in 3.12 #103348

: typing: Don't unnecessarily call `_get_protocol_attrs…

Backport performance improvements to runtime-checkable protocols python/typing_extensions#137

[Bug] typing_extensions.Protocol unsupported under typing_extensions ≥ 4.6.0 beartype/beartype#241