Add a `collection.abc.Function` ABC for function-like objects
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza revisando el issue de Cython enlazado y las tres implementaciones de ejemplo que detectan funciones de Cython. No se nombra ningún archivo ni prueba de CPython, así que el primer paso es localizar las áreas relevantes de ABC e introspección y confirmar la API propuesta con los maintainers. Se considera completado cuando exista un diseño aceptado para el nuevo ABC, sus registros y pruebas, además del cambio correspondiente en backports_abc.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- developer-experience
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 32/100