Title: Add a `collection.abc.Function` ABC for function-like objects · Issue #131983 · python/cpython · GitHub
Open Graph Title: Add a `collection.abc.Function` ABC for function-like objects · Issue #131983 · python/cpython
X Title: Add a `collection.abc.Function` ABC for function-like objects · Issue #131983 · python/cpython
Description: Feature or enhancement Proposal: In the Cython project, we generate a function type that is mostly compatible with Python's function type. There is currently no (simple/reasonably fast) way to detect this kind of object, but there are us...
Open Graph Description: Feature or enhancement Proposal: In the Cython project, we generate a function type that is mostly compatible with Python's function type. There is currently no (simple/reasonably fast) way to dete...
X Description: Feature or enhancement Proposal: In the Cython project, we generate a function type that is mostly compatible with Python's function type. There is currently no (simple/reasonably fast) way to ...
Opengraph URL: https://github.com/python/cpython/issues/131983
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add a `collection.abc.Function` ABC for function-like objects","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nIn the Cython project, we generate a function type that is mostly compatible with Python's function type. There is currently no (simple/reasonably fast) way to detect this kind of object, but there are use cases and Cython aware projects have found their workarounds in one way or another. But it still means that all code that wants to specially support both Python and Cython functions in the same (or similar) way needs to do something special to detect both, rather than just saying \"is this a function?\".\n\nThere should be an `abc.Function` ABC that other function implementations can register with.\nThat would make the detection a simple and straight forward `isinstance(obj, abc.Function)`.\n\n`inspect.isfunction()` does not help since it specifically tests that the object *is* a Python function object, which is good to have, simple and fills a need. The ABC is for use cases where code needs to test whether an object is a callable with a function-like interface, e.g. for introspection, signature, code-like object, etc., however complete that implementation then is.\n\nThis is probably also relevant for other tools like `mypyc` or `numba` that provide binary functions to Python in one way or another.\n\nI'd also add this ABC to the PyPI package `backports_abc` which provides missing ABCs for older Pythons.\n\n### Has this already been discussed elsewhere?\n\nNo response given\n\n### Links to previous discussion of this feature:\n\nMake `inspect.isfunction()` support Cython functions:\nhttps://github.com/cython/cython/issues/6379\n\nSome code trying to detect Cython functions:\n* https://github.com/vmware-archive/pop/blob/f3a67f913ee92cf855889719a23f662dd435f39d/pop/loader.py#L222\n* https://github.com/sphinx-doc/sphinx/blob/a6d7ae16739bf92a032a7c4df0297db7cf120ec9/sphinx/util/inspect.py#L342-L347\n* https://github.com/quora/qcore/blob/f93ccc0f04858f1c606d3b95f05ff315f4fd47bf/qcore/inspection.py#L151-L163","author":{"url":"https://github.com/scoder","@type":"Person","name":"scoder"},"datePublished":"2025-04-01T15:59:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/131983/cpython/issues/131983"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f2d51956-9fd3-f7ff-8cc6-6b2b6c2db073 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A23A:119F46:196E146:24688AA:6A635E55 |
| html-safe-nonce | 5bacefcff074eef414095b4686b316d4fff545f7eedc410702f88cded0d6171f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjNBOjExOUY0NjoxOTZFMTQ2OjI0Njg4QUE6NkE2MzVFNTUiLCJ2aXNpdG9yX2lkIjoiMjY5MzUxOTg4MDI2MDY0MDM0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 945c3b6c7a41d939a114c6bcad17e4c7e84a0b445be4dd3ff85a7efcc3fe2415 |
| hovercard-subject-tag | issue:2963889039 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/131983/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5ff4303efc56d8e7e5a9d03e2d51cfda66c9f063f79fb457a54869616733b01b/python/cpython/issues/131983 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5ff4303efc56d8e7e5a9d03e2d51cfda66c9f063f79fb457a54869616733b01b/python/cpython/issues/131983 |
| og:image:alt | Feature or enhancement Proposal: In the Cython project, we generate a function type that is mostly compatible with Python's function type. There is currently no (simple/reasonably fast) way to dete... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | scoder |
| hostname | github.com |
| expected-hostname | github.com |
| None | 59e55daad7174ca59d63c6974d58276ccb5477442e550bebb3c035e1bef11c94 |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 71b1218de2f2ab29c4d5ce72568e68e2c56044c6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width