| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| tvars = typing._collect_type_vars(cls.__orig_bases__) | ||
| tvars = _collect_type_vars(cls.__orig_bases__) |
There was a problem hiding this comment.
This change was required because typing._collect_type_vars doesn't exist on Python 3.11 (but typing_extensions._collect_type_vars does), and with this PR, we now re-implement Protocol on <=3.11, whereas we previously only re-implemented it on <=3.9
Sorry, something went wrong.
| def _is_unpack(obj): | ||
| return get_origin(obj) is Unpack |
There was a problem hiding this comment.
This change was required in order for tests to pass on Python 3.11. Without this change, a function somewhere was failing with NameError when the tests were run on Python 3.11, because the function was calling _is_unpack(), and we previously only defined _is_unpack on Python <=3.10.
Sorry, something went wrong.
|
We could possibly also backport "fast versions" of the runtime-checkable protocols that the typing module provides: https://docs.python.org/3/library/typing.html#protocols As a result of the performance improvements I'm backporting here, isinstance() checks against the typing versions of these protocols should be much faster on 3.12 than it is on 3.11. |
Sorry, something went wrong.
|
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. I did a bisect of every change between typing-extensions 4.5.0 and 4.6.0, and this was pointed out as the culprit. I've had a look at the code changes here but don't have a good enough grasp of what's going wrong that is causing this to fail. This seems to be the relevant Pydash code that relates to the error: |
Sorry, something went wrong.
|
Cheers! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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:
- 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
Here is a benchmark script:Note that if we choose to backport python/cpython#103034 (using inspect.getattr_static instead of getattr in _ProtocolMeta.__instancecheck__), it will undo a lot of the performance improvements that this PR brings. I leave the decision of whether or not to backport that PR to another PR/issue.