Add a `collection.abc.Function` ABC for function-like objects
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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 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?".
There should be an abc.Function ABC that other function implementations can register with.
That would make the detection a simple and straight forward isinstance(obj, abc.Function).
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.
This is probably also relevant for other tools like mypyc or numba that provide binary functions to Python in one way or another.
I'd also add this ABC to the PyPI package backports_abc which provides missing ABCs for older Pythons.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
Make inspect.isfunction() support Cython functions:
https://github.com/cython/cython/issues/6379
Some code trying to detect Cython functions:
- https://github.com/vmware-archive/pop/blob/f3a67f913ee92cf855889719a23f662dd435f39d/pop/loader.py#L222
- https://github.com/sphinx-doc/sphinx/blob/a6d7ae16739bf92a032a7c4df0297db7cf120ec9/sphinx/util/inspect.py#L342-L347
- https://github.com/quora/qcore/blob/f93ccc0f04858f1c606d3b95f05ff315f4fd47bf/qcore/inspection.py#L151-L163
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンクされている Cython issue と、Cython 関数を検出する 3 つの実装例を確認します。CPython のファイルやテストは指定されていないため、最初のステップは、関連する ABC とイントロスペクションの領域を特定し、提案された API について maintainer と確認することです。完了の条件は、新しい ABC、その登録およびテストについて承認された設計と、それに対応する backports_abc の変更があることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- developer-experience
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 32/100