Weird `int.__str__` behaviour inside sub-interpreters
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Bug report
Bug description:
Hi Python maintainers!
I noticed something weird when using subinterpreters, while converting an Enum to string I get an unexpected result. This occurs in Python 3.12 and 3.13.
Here's an script to reproduce it:
import _xxsubinterpreters as interpreters
script = """from enum import _simple_enum, IntEnum
@_simple_enum(IntEnum)
class MyEnum:
DATA = 1
print(str(MyEnum.DATA))
"""
exec(script)
# Output: 1
interp_id = interpreters.create(isolated=False)
interpreters.run_string(interp_id, script)
# Output: <MyEnum.DATA: 1>, Expected: 1
In all python versions previous to 3.12 this prints "1" two times, on newer versions I get <MyEnum.DATA: 1> when running inside a subinterpreter. For some reason, the __str__ function being used is different on new Python versions.
I also noticed that the function pointed by __str__ is different inside and outside the subinterpreter.
Outside:
...
print(MyEnum.DATA.__str__)
# Output: <method-wrapper '__repr__' of MyEnum object at 0x7f9a09a2e910>
Inside:
...
print(MyEnum.DATA.__str__)
# Output: <method-wrapper '__str__' of MyEnum object at 0x7f9a099a5e90>
NOTE: I'm creating subinterpreters passing the
isolated=Falseflag, which uses the Legacy init config.
I first noticed the error on MacOS, then reproduced using Docker with various Python versions.
I hope this is enough to get to the source of the issue.
Appreciate all your work and effort on building Python, thank you!
CPython versions tested on:
3.8, 3.9, 3.10, 3.11, 3.12, 3.13
Operating systems tested on:
Linux, macOS
Linked PRs
- gh-117660
- gh-121602
- gh-121630
- gh-121632
- gh-121636
- gh-121862
- gh-121882
- gh-121932
- gh-122192
- gh-122195
- gh-122197
- gh-122241
- gh-122248
- gh-122249
- gh-122250
- gh-122865
- gh-122866
- gh-122867
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 exécuter le reproducteur _xxsubinterpreters fourni avec enum._simple_enum et comparez MyEnum.DATA.str à l’intérieur et à l’extérieur du sous-interpréteur. Suivez les points d’entrée pertinents du runtime de CPython et de enum, puis vérifiez que le comportement correspond à la conversion en chaîne attendue pour les versions de Python concernées ; l’issue répertorie de nombreux PRs liés à examiner en premier.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100