File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -55,9 +55,16 @@ class env:
55
55
"_direct_write" , "_reserved_names" )
56
56
_direct_write = ("_env" , "_finalized" )
57
57
58
+ # For pickle support, since unpickling calls `__new__` but not `__init__`.
59
+ # If `self._env` is not present, `__getattr__` will crash with an infinite loop. So create it as early as possible.
60
+ def __new__ (cls , ** kwargs ):
61
+ instance = super ().__new__ (cls )
62
+ instance ._env = {}
63
+ instance ._finalized = False # "let" sets this once env setup done
64
+ instance .__init__ (** kwargs )
65
+ return instance
66
+
58
67
def __init__ (self , ** bindings ):
59
- self ._env = {}
60
- self ._finalized = False # "let" sets this once env setup done
61
68
for name , value in bindings .items ():
62
69
setattr (self , name , value )
63
70
You can’t perform that action at this time.
0 commit comments