Replace ctypes.DllGetClassObject and remove DllCanUnloadNow
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando la pull request collegata gh-127766 e le modifiche proposte nell’issue per ctypes.DllGetClassObject e DllCanUnloadNow. Traccia gli hook esistenti di ctypes e l’integrazione di comtypes.server.inprocserver descritta qui; il lavoro sarà completato quando l’API e il comportamento di deprecazione saranno concordati, sarà implementato senza causare regressioni involontarie in comtypes e sarà coperto dai test pertinenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- operating-systems
- Tipo di issue
- Refactoring
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 20/100