cloudpipe / cloudpipe/cloudpickle
Unable to pickle functions that are decorated with `functools.lru_cache()`
- Lingua principale
- Python
- Stelle
- 1.9k
- Fork
- 195
- Merge medio
- 1g 10h
- PR unite (30g)
- 1
Descrizione
## Observed behavior
The cloudpickle module is unable to pickle functions that are cached via the `functools.lru_cache` decorator function.
The following minimal example triggers the issue on Python 3.6.5 and cloudpickle version 0.5.3:
```python
# minimal.py
from functools import lru_cache
import cloudpickle
@lru_cache()
def cached_func():
pass
cloudpickle.dumps(cached_func)
```
Resulting in the following traceback:
```bash
$ python minimal.py
Traceback (most recent call last):
File "minimal.py", line 8, in
cloudpickle.dumps(cached_func)
File "/Users/csadorf/miniconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py", line 895, in dumps
cp.dump(obj)
File "/Users/csadorf/miniconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py", line 268, in dump
return Pickler.dump(self, obj)
File "/Users/csadorf/miniconda3/lib/python3.6/pickle.py", line 409, in dump
self.save(obj)
File "/Users/csadorf/miniconda3/lib/python3.6/pickle.py", line 507, in save
self.save_global(obj, rv)
File "/Users/csadorf/miniconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py", line 642, in save_global
return self.save_dynamic_class(obj)
File "/Users/csadorf/miniconda3/lib/python3.6/site-packages/cloudpickle/cloudpickle.py", line 497, in save_dynamic_class
self.save_reduce(tp, (obj.__name__, obj.__bases__, type_kwargs), obj=obj)
AttributeError: 'functools._lru_cache_wrapper' object has no attribute '__bases__'
```
Versions:
```bash
$ python -V
Python 3.6.5 :: Anaconda, Inc.
$ python -c "import cloudpickle; print(cloudpickle.__version__)"
0.5.3
```
## Expected behavior
The cloudpickle module should handle cached functions by either pickling or ignoring the cache or at least should fail with a descriptive error message.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Start with the minimal.py example from the issue and reproduce the AttributeError using a function decorated with functools.lru_cache(). Trace cloudpickle's handling of the cached function and verify that the expected behavior is covered by a test, including successful pickling or a descriptive failure.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100