Introspection: use typing_extensions.Buffer instead of collections.abc.Buffer (py312+) - #6395
Conversation
….abc.Buffer` (py312+)
4eade08 to
c8c7012
Compare
|
@jorenham just as a datapoint, I'm no PyO3 maintainer: In recently merged PR #6362, there was a bit of back and forth of how to deal with typing features not available to all Python versions. In that PR, things converged to let it render, depending on Python version, to the variant with maximum portability or compatibility. In this specific instance, a disjoint_base pointer was used internally, but was rendered to Similarly, one could introduce a similar rule here, i.e. emit This is because using Verified empirically with # test_buffer.py
from typing_extensions import Buffer |
Ah yea, that's indeed a problem. Doing it as you suggest crossed my mind, but to be honest I was just being lazy and went with the easy solution :p |
…on<3.12` Co-authored-by: Jonas Dedden <mail@jonas-dedden.de>
Tpt
left a comment
There was a problem hiding this comment.
Thank you! Just a test issue and some ideas where push backs are more than welcome
…ffer` fix Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr>
Merging this PR will improve performance by 12.77%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | into_biguint_zero |
1.4 µs | 1.2 µs | +13.49% |
| ⚡ | into_biguint_small |
1.5 µs | 1.4 µs | +12.06% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing jorenham:introspection/typing_extensions.Buffer (20edb7e) with main (360f899)
Footnotes
-
6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
collections.abc.Bufferwas added in Python 3.12 (docs), but PyO3 also supports older versions. By usingtyping_extensions.Bufferinstead, this will no longer lead to typing issues. Note that within .pyi stubstyping_extensionsis always available, even if not installed, becausetyping_extensionsis bundled as part of the stdlib stubs through typeshed: https://github.com/python/typeshed/blob/main/stdlib/typing_extensions.pyi