Skip to content

Commit 4f79f24

Browse files
authored
Remove _env instance attribute from Element (#145)
1 parent 27630e6 commit 4f79f24

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

branca/element.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class Element:
5454
def __init__(self, template=None, template_name=None):
5555
self._name = "Element"
5656
self._id = hexlify(urandom(16)).decode()
57-
self._env = ENV
5857
self._children = OrderedDict()
5958
self._parent = None
6059
self._template_str = template
@@ -67,19 +66,16 @@ def __init__(self, template=None, template_name=None):
6766

6867
def __getstate__(self):
6968
"""Modify object state when pickling the object.
70-
jinja2 Environment cannot be pickled, so set
71-
the ._env attribute to None. This will be added back
72-
when unpickling (see __setstate__)
69+
70+
jinja2 Templates cannot be pickled, so remove the instance attribute
71+
if it exists. It will be added back when unpickling (see __setstate__).
7372
"""
7473
state: dict = self.__dict__.copy()
75-
state["_env"] = None
7674
state.pop("_template", None)
7775
return state
7876

7977
def __setstate__(self, state: dict):
80-
"""Re-add ._env attribute when unpickling"""
81-
state["_env"] = ENV
82-
78+
"""Re-add _template instance attribute when unpickling"""
8379
if state["_template_str"] is not None:
8480
state["_template"] = Template(state["_template_str"])
8581
elif state["_template_name"] is not None:

0 commit comments

Comments
 (0)