cloudpipe / cloudpipe/cloudpickle

TypeError serializing a classmethod that refers to a module ContextVar (Pickle can) - Python 3.8

Open
#387 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.9k
Forks
195
Avg merge
1d 10h
Merged PRs (30d)
1

Description

testcontext.py
```python
import contextvars
a = contextvars.ContextVar(__name__)
class A:
@classmethod
def g(cls):
print(1)
@classmethod
def f(cls):
print(a.get(None))

def h(self):
print(a.get(None))

#from testcontext import A; from cloudpickle import dumps; dumps(A.f)
#> TypeError
```

```shell
Python 3.8.3 | packaged by conda-forge | (default, Jun 1 2020, 17:43:00)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from testcontext import A; from cloudpickle import dumps; dumps(A.f)
Traceback (most recent call last):
File "", line 1, in
File "/home/ma/miniconda3/lib/python3.8/site-packages/cloudpickle/cloudpickle_fast.py", line 63, in dumps
cp.dump(obj)
File "/home/ma/miniconda3/lib/python3.8/site-packages/cloudpickle/cloudpickle_fast.py", line 548, in dump
return Pickler.dump(self, obj)
TypeError: cannot pickle 'ContextVar' object
>>> from pickle import dumps
>>> dumps(A.f)
b'\x80\x04\x954\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x07getattr\x94\x93\x94\x8c\x0btestcontext\x94\x8c\x01A\x94\x93\x94\x8c\x01f\x94\x86\x94R\x94.'
>>>
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.