datetime: Stop Exposing Process-Global Objects in the datetime C-API
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 36k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Feature or enhancement
Proposal:
The datetime module has its own C-API which is enabled with PyDateTime_IMPORT. From the docs:
Before using any of these functions, the header file datetime.h must be included in your source
(note that this is not included by Python.h), and the macro PyDateTime_IMPORT must be invoked,
usually as part of the module initialisation function. The macro puts a pointer to a C structure into
a static variable, PyDateTimeAPI, that is used by the following macros.
My main concern is that the PyDateTimeAPI struct is a process-global value, but it exposes object pointers (which should always be per-interpreter). We have worked around this in 3.13+, but it would be better if we could make the objects per-interpreter.
FTR, here are the objects exposed directly by PyDateTimeAPI:
- (static type)
PyDateTime_DateType - (static type)
PyDateTime_DateTimeType - (static type)
PyDateTime_TimeType - (static type)
PyDateTime_DeltaType - (static type)
PyDateTime_TZInfoType - (singleton)
utc_timezone(an instance ofPyDateTime_TimeZoneType)
exposed indirectly:
- (static type)
PyDateTime_TimeZoneType
In order to make these objects per-interpreter, it would require changes to the datetime C-API. [^1] I expect we would leave PyDateTime_IMPORT alone. Instead, we'd need to update the macros in datetime.h to get the objects from the module associated with the current interpreter. [^2]
[^1]: These would be ABI-incompatible changes, which wouldn't be a problem unless the datetime C-API is part of the limited API).
[^2]: Anyone who is accessing the PyDateTimeAPI struct directly would have to change their code. It might make sense to provide a getter function/macro for each of the objects.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la documentation de la datetime C-API et les macros de datetime.h décrites dans la proposition, puis examinez comment PyDateTimeAPI expose les types listés et utc_timezone. Le travail est terminé lorsque ces objets sont propres à chaque interpréteur, que PyDateTime_IMPORT reste inchangé et que toute modification nécessaire des getters ou de l’accès direct est documentée et testée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- c, python
- Domaine
- api
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100