Skip to content

Compiler should fall back to higher pickle protocols in some cases #291

Description

@gilch

There are cases where protocol 0 doesn't work at all, but a higher protocol might:

#> |class Box:__slots__='item'|
>>> class Box:__slots__='item'
#> .#(Box)
>>> # CompileError

(>   >  > >><__main__.Box object at 0x000001B3E0C344C0><< <  <   <)
# Compiler.pickle() TypeError:
#  cannot pickle 'Box' object: a class that defines __slots__ without defining __getstate__ cannot be pickled with protocol 0

#> (pickle..dumps (Box))
>>> __import__('pickle').dumps(
...   Box())
b'\x80\x04\x95\x17\x00\x00\x00\x00\x00\x00\x00\x8c\x08__main__\x94\x8c\x03Box\x94\x93\x94)\x81\x94.'

The compiler already checks if the highest protocol is shorter and uses it in some cases. It just needs to not give up if protocol 0 fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions