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:
5555 "_direct_write" , "_reserved_names" )
5656 _direct_write = ("_env" , "_finalized" )
5757
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+
5867 def __init__ (self , ** bindings ):
59- self ._env = {}
60- self ._finalized = False # "let" sets this once env setup done
6168 for name , value in bindings .items ():
6269 setattr (self , name , value )
6370
You can’t perform that action at this time.
0 commit comments