Skip to content

Commit

Permalink
Fix unpickling FuncCode instances
Browse files Browse the repository at this point in the history
This used to be an old-style class, and the pickle calls the OBJ opcode
(which for old-style classes creates an instance without calling __init__)
and later the BUILD opcode which calls __setstate__. Now that the class
is new-style, the OBJ opcode calls __init__, which breaks because the
pickle doesn't include args for __init__. So the workaround here is to
make __init__ accept no args (the object dict will still get set by the
subsequent BUILD op). Once the new-style object gets re-pickled it will
use the NEWOBJ opcode instead of OBJ, so unpickling will only call __new__
and not __init__.
  • Loading branch information
davisagli authored and thet committed Apr 3, 2017
1 parent 69a7c2c commit 161e7b2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Shared/DC/Scripts/Signature.py
Expand Up @@ -21,8 +21,8 @@
@total_ordering
class FuncCode(object):

def __init__(self, varnames, argcount):
self.co_varnames = varnames
def __init__(self, varnames=None, argcount=0):
self.co_varnames = varnames or ()
self.co_argcount = argcount

def __eq__(self, other):
Expand Down

0 comments on commit 161e7b2

Please sign in to comment.