python / python/cpython

Inconsistency in handling None handlers in the Python and C implementations of pickle

Ouverte
#93,627 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

3.10 3.11 3.12 type-bug
Langage dominant
Python
Étoiles
77.2k
Forks
36k
Métriques de merge des PR
Métriques de PR en attente

Description

In the Python implementation of pickle setting some handlers to None causes a fallback to other methods.

  • Setting Pickler.reducer_override to None has the same effect as not setting this attribute -- falling back to other methods.
  • Setting the dispatch_table to None leads to falling back to __reduce_ex__.
  • Setting the __reduce_ex__ attribute to None leads to falling back to __reduce__.
  • Setting the __setstate__ attribute to None leads to falling back to the default implementation of __setstate__ (setting __dict__ and slots).

In the C implementation all this leads to TypeError: 'NoneType' object is not callable.

The copy module follows the Python implementation of pickle, except that it fails for any false value of __reduce__, not just None.

In most other code setting a dunder method to None leads to a TypeError (either raise explicitly or just generic "'NoneType' object is not callable").

We should decide what behavior should be in the pickle and copy module. On one hand, the Python implementation was primary. On other hand, it was inconsistent between the pickle and copy modules and was already changed in the past, the C implementation of pickle is now used by most users, and it is more consistent with other code.

See also:
https://mail.python.org/archives/list/python-dev@python.org/thread/YGAK34DRWJFSIV2VZ4NC2J24XO37GCMM/
https://docs.python.org/3.10/reference/datamodel.html#id2
https://github.com/python/cpython/issues/70146
https://github.com/python/cpython/issues/55781
https://github.com/python/cpython/issues/60755

Linked PRs
  • gh-103035
  • gh-109498

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par lire les implémentations Python et C de pickle et du module copy, puis examinez les pull requests liées gh-103035 et gh-109498. La finalisation nécessite de s’accorder sur le comportement des gestionnaires None et d’assurer un traitement cohérent dans toutes les implémentations concernées.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
c, python
Domaine
backend
Type d'issue
Bug
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.