Inconsistency in handling None handlers in the Python and C implementations of pickle
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Merge medio
- 1g 9h
- PR unite (30g)
- 558
Descrizione
In the Python implementation of pickle setting some handlers to None causes a fallback to other methods.
- Setting
Pickler.reducer_overrideto None has the same effect as not setting this attribute -- falling back to other methods. - Setting the
dispatch_tableto 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
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 leggendo le implementazioni Python e C di pickle e del modulo copy, quindi esamina le pull request collegate gh-103035 e gh-109498. Per considerare il lavoro completato, è necessario concordare il comportamento degli handler None e garantire una gestione coerente tra tutte le implementazioni interessate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100