<s> import dill <EOL> import sys <EOL> dill . settings [ '<STR_LIT>' ] = True <EOL> class _class : <EOL> def _method ( self ) : <EOL> pass <EOL> def ok ( self ) : <EOL> return True <EOL> class _class2 : <EOL> def __call__ ( self ) : <EOL> pass <EOL> def ok ( self ) : <EOL> return True <EOL> class _newclass ( object ) : <EOL> def _method ( self ) : <EOL> pass <EOL> def ok ( self ) : <EOL> return True <EOL> class _newclass2 ( object ) : <EOL> def __call__ ( self ) : <EOL> pass <EOL> def ok ( self ) : <EOL> return True <EOL> class _meta ( type ) : <EOL> pass <EOL> def __call__ ( self ) : <EOL> pass <EOL> def ok ( self ) : <EOL> return True <EOL> _mclass = _meta ( "<STR_LIT>" , ( object , ) , { "<STR_LIT>" : __call__ , "<STR_LIT>" : ok } ) <EOL> del __call__ <EOL> del ok <EOL> o = _class ( ) <EOL> oc = _class2 ( ) <EOL> n = _newclass ( ) <EOL> nc = _newclass2 ( ) <EOL> m = _mclass ( ) <EOL> assert dill . pickles ( o ) <EOL> assert dill . pickles ( oc ) <EOL> assert dill . pickles ( n ) <EOL> assert dill . pickles ( nc ) <EOL> assert dill . pickles ( m ) <EOL> clslist = [ _class , _class2 , _newclass , _newclass2 , _mclass ] <EOL> objlist = [ o , oc , n , nc , m ] <EOL> _clslist = [ dill . dumps ( obj ) for obj in clslist ] <EOL> _objlist = [ dill . dumps ( obj ) for obj in objlist ] <EOL> for obj in clslist : <EOL> globals ( ) . pop ( obj . __name__ ) <EOL> del clslist <EOL> for obj in [ '<STR_LIT:o>' , '<STR_LIT>' , '<STR_LIT:n>' , '<STR_LIT>' ] : <EOL> globals ( ) . pop ( obj ) <EOL> del objlist <EOL> del obj <EOL> for obj , cls in zip ( _objlist , _clslist ) : <EOL> _cls = dill . loads ( cls ) <EOL> _obj = dill . loads ( obj ) <EOL> assert _obj . ok ( ) <EOL> assert _cls . ok ( _cls ( ) ) <EOL> if _cls . __name__ == "<STR_LIT>" : <EOL> assert type ( _cls ) . __name__ == "<STR_LIT>" <EOL> assert dill . pickles ( type ( None ) ) <EOL> if hex ( sys . hexversion ) >= '<STR_LIT>' : <EOL> from collections import namedtuple <EOL> Z = namedtuple ( "<STR_LIT>" , [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> Zi = Z ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> X = namedtuple ( "<STR_LIT:Y>" , [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> X . __name__ = "<STR_LIT:X>" <EOL> Xi = X ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> assert Z == dill . loads ( dill . dumps ( Z ) ) <EOL> assert Zi == dill . loads ( dill . dumps ( Zi ) ) <EOL> assert X == dill . loads ( dill . dumps ( X ) ) <EOL> assert Xi == dill . loads ( dill . dumps ( Xi ) ) <EOL> try : <EOL> import numpy as np <EOL> class TestArray ( np . ndarray ) : <EOL> def __new__ ( cls , input_array , color ) : <EOL> obj = np . asarray ( input_array ) . view ( cls ) <EOL> obj . color = color <EOL> return obj <EOL> def __array_finalize__ ( self , obj ) : <EOL> if obj is None : <EOL> return <EOL> if isinstance ( obj , type ( self ) ) : <EOL> self . color = obj . color <EOL> def __getnewargs__ ( self ) : <EOL> return np . asarray ( self ) , self . color <EOL> a1 = TestArray ( np . zeros ( <NUM_LIT:100> ) , color = '<STR_LIT>' ) <EOL> assert dill . pickles ( a1 ) <EOL> assert a1 . __dict__ == dill . copy ( a1 ) . __dict__ <EOL> a2 = a1 [ <NUM_LIT:0> : <NUM_LIT:9> ] <EOL> assert dill . pickles ( a2 ) <EOL> assert a2 . __dict__ == dill . copy ( a2 ) . __dict__ <EOL> class TestArray2 ( np . ndarray ) : <EOL> color = '<STR_LIT>' <EOL> a3 = TestArray2 ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> a3 . color = '<STR_LIT>' <EOL> assert dill . pickles ( a3 ) <EOL> assert a3 . __dict__ == dill . copy ( a3 ) . __dict__ <EOL> except ImportError : pass <EOL> class A ( object ) : <EOL> @ classmethod <EOL> def test ( cls ) : <EOL> pass <EOL> a = A ( ) <EOL> res = dill . dumps ( a ) <EOL> new_obj = dill . loads ( res ) <EOL> new_obj . __class__ . test ( ) <EOL> class X ( object ) : <EOL> __slots__ = [ '<STR_LIT:x>' ] <EOL> def __init__ ( self , x ) : <EOL> self . x = x <EOL> value = <NUM_LIT> <EOL> x = X ( value ) <EOL> assert dill . pickles ( X ) <EOL> assert dill . pickles ( x ) <EOL> assert dill . pickles ( X . x ) <EOL> assert dill . copy ( x ) . x == value </s>
