Replace ctypes.DllGetClassObject and remove DllCanUnloadNow
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
As far as I can tell, these functions are hooks: third-party code is meant to replace them.
Their implementation in ctypes (i.e. their default behaviour) is to import and call the same-named functions from a third-party library, comtypes.server.inprocserver. This is not good. comtypes should instead register their hook on import.
Here's a possible plan to make the API boundary better without breaking users.
DllCanUnloadNow
While the Python interpreter is running, it is not safe to unload the shared library that contains _ctypes. Therefore:
- The C function
DllCanUnloadNowexported from _ctypes should be changed to always returnS_FALSE. We should change that now, without a deprecation period. (Note that thecomtypeshook already does this.) - We should stop importing and calling
comtypes.server.inprocserver. I'm not sure about the necessary deprecation period, but I think that it should be a non-breaking change and can also be done immediately. Or is someone relying on it for side effects? O_o - Setting and getting the hook should be deprecated. In about Python 3.18 we should stop calling it, and remove it.
DllGetClassObject
This one, on the other hand, sounds like a useful hook. It also looks like an inprocess COM server need a special build so it's not useful to allow multiple hooks -- replacing a global one is enough. Is that so?
If yes:
ctypes.DllGetClassObject(the default implementation) should raise aDeprecationWarning. In about Python 3.18, it should be changed to do nothing, just, returnCLASS_E_CLASSNOTAVAILABLE.comtypesshould be changed: on import, it should replacectypes.DllGetClassObjectwith its own hook.
This should ensure that old versions of comtypes still work as before (until after the deprecation period).
Does that sound reasonable?
cc @junkmd
Linked PRs
- gh-127766
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
Empieza revisando el pull request enlazado gh-127766 y los cambios propuestos en el issue para ctypes.DllGetClassObject y DllCanUnloadNow. Rastrea los hooks existentes de ctypes y la integración de comtypes.server.inprocserver descrita aquí; el trabajo estará terminado cuando la API y el comportamiento de deprecación estén acordados, se haya implementado sin provocar regresiones no deseadas en comtypes y esté cubierto por las pruebas relevantes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- operating-systems
- Tipo de issue
- Refactorización
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 20/100