Title: gh-60074: add new stable API function PyType_FromMetaclass by wjakob · Pull Request #93012 · python/cpython · GitHub
Open Graph Title: gh-60074: add new stable API function PyType_FromMetaclass by wjakob · Pull Request #93012 · python/cpython
X Title: gh-60074: add new stable API function PyType_FromMetaclass by wjakob · Pull Request #93012 · python/cpython
Description: TL;DR: Numerous flagship Python packages internally rely on pybind11 to bridge C++ and Python. This includes SciPy, PyTorch, Tensorflow, JAX, and many others. This PR adds critical functionality needed to eventually move more of them onto the Py_LIMITED_API and thereby simplify deployment of binary wheels. Context: C++ <-> Python binding tools like pybind11 and nanobind require the ability to instantiate types using a custom metaclass. pybind11 uses them to install custom handling for some type-related operations, and nanobind goes even further by storing binding-related data structures in an enlarged PyHeapTypeObject allocated by a metaclass. Unfortunately is not currently possible to dynamically create suitable heap types using the Py_LIMITED_API, which means that each extension library using these tools must be compiled many times for redistribution. I believe that it would be useful to the Python community to at least optionally support Py_LIMITED_API in these tools, but this requires a small change in CPython. This pull request is another attempt at addressing the issue pointed out in issue #60074. It adds a new stable API function PyType_FromMetaclass that mirrors the behavior of PyType_FromModuleAndSpec except that it takes an additional metaclass argument. I used this PR to create a proof-of-concept version of nanobind (limited_api branch) that dynamically create types using the limited API. It works 🎉 . I have a somewhat audacious request, which is that this change is considered for Python 3.11 despite having recently entered feature freeze. I believe that this change is small enough and of significant utility for the wider Python community (potentially even for other groups working on bindings like SWIG or Cython)
Open Graph Description: TL;DR: Numerous flagship Python packages internally rely on pybind11 to bridge C++ and Python. This includes SciPy, PyTorch, Tensorflow, JAX, and many others. This PR adds critical functionality ne...
X Description: TL;DR: Numerous flagship Python packages internally rely on pybind11 to bridge C++ and Python. This includes SciPy, PyTorch, Tensorflow, JAX, and many others. This PR adds critical functionality ne...
Opengraph URL: https://github.com/python/cpython/pull/93012
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5155d16f-24f7-9f5c-7895-02f8c3855891 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A888:174FB1:4A21B9:650F93:696AAA0F |
| html-safe-nonce | b475bf580ddff4d4a7abfa3ecfcf72542efee16d944dcf8aced1ec5e95caa3e6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODg4OjE3NEZCMTo0QTIxQjk6NjUwRjkzOjY5NkFBQTBGIiwidmlzaXRvcl9pZCI6Ijc1NjY3OTU1MzMyODQxOTA3MzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3914a762b2c41cb309eb1c37bd57d92493933648b9ad08268b3406d014714a4c |
| hovercard-subject-tag | pull_request:942617153 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/93012/files |
| twitter:image | https://avatars.githubusercontent.com/u/1203629?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1203629?s=400&v=4 |
| og:image:alt | TL;DR: Numerous flagship Python packages internally rely on pybind11 to bridge C++ and Python. This includes SciPy, PyTorch, Tensorflow, JAX, and many others. This PR adds critical functionality ne... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3eaf9b8cf1badcd7041a8ad480b9d9b28bea0ef1cc821ca9ff20f2cc7f4fe4b9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | dd9a979046e6382bd084e2bd873bf65f797125ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width