Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudpickle is not compatible with Python 3.11 #466

Closed
frenzymadness opened this issue Mar 10, 2022 · 4 comments · Fixed by #467
Closed

cloudpickle is not compatible with Python 3.11 #466

frenzymadness opened this issue Mar 10, 2022 · 4 comments · Fixed by #467

Comments

@frenzymadness
Copy link
Contributor

The tests are failing, for example:

obj = [<function CloudPickleTest.test_closure_interacting_with_a_global_variable.<locals>.f0 at 0x7fe96122df80>, <function CloudPickleTest.test_closure_interacting_with_a_global_variable.<locals>.f1 at 0x7fe96122dda0>]
protocol = 5

    def pickle_depickle(obj, protocol=cloudpickle.DEFAULT_PROTOCOL):
        """Helper function to test whether object pickled with cloudpickle can be
        depickled with pickle
        """
>       return pickle.loads(cloudpickle.dumps(obj, protocol=protocol))
E       TypeError: code expected at least 18 arguments, got 16

obj        = [<function CloudPickleTest.test_closure_interacting_with_a_global_variable.<locals>.f0 at 0x7fe96122df80>, <function CloudPickleTest.test_closure_interacting_with_a_global_variable.<locals>.f1 at 0x7fe96122dda0>]
protocol   = 5

tests/cloudpickle_test.py:81: TypeError

Failed tests are:
FAILED tests/cloudpickle_test.py::CloudPickleTest::test_abc - TypeError: code expected at l...
FAILED tests/cloudpickle_test.py::CloudPickleTest::test_abstracts - TypeError: code expecte...
FAILED tests/cloudpickle_test.py::CloudPickleTest::test_bound_classmethod - TypeError: code...
FAILED tests/cloudpickle_test.py::CloudPickleTest::test_classmethod - TypeError: code expec...
FAILED tests/cloudpickle_test.py::CloudPickleTest::test_closure_interacting_with_a_global_variable

@ogrisel
Copy link
Contributor

ogrisel commented Mar 10, 2022

Thanks for the report, would you be interested in contributing a pull request?

@frenzymadness
Copy link
Contributor Author

I'm not sure I understand it well enough any my time is very limited now but I can try it if nobody will be faster.

@frenzymadness
Copy link
Contributor Author

So, I've spent a few hours with this and I'm now certainly smarter than I was but the problem is still unsolved. It seems that the problem is caused by the differences in code objects in Python 3.11 – there are at least two new attributes for code objects co_columntable and co_qualname.
I know about those two new attributes and also the error message above says something about two missing arguments.
So, I've decided to debug pickle to see where in the list of attrs of a codeobject these two should be added but I¨ve realized that pickle serializes only references (in case of functions) so I cannot use that as a source of information I need.
It also seems that dir(foo.__code__) uses alphabetical ordering.

The remaining question is: where can I find the expected order of codeobject attributes expected by pickle.loads?

@ssanderson
Copy link

ssanderson commented Mar 16, 2022

@frenzymadness very likely what needs to be updated is _code_reduce in cloudpickle_fast.py. You can see there are already several branches there for versions of python that have added new code object fields.

The order of the arguments is going to want to be the order that types.CodeType expects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants