refactor: use copy() instead of __copy__

This commit is contained in:
Juro Oravec 2024-04-16 23:15:22 +02:00
parent 091a692993
commit 691b663ed5
2 changed files with 4 additions and 2 deletions

View file

@ -5,6 +5,7 @@ pass data across components, nodes, slots, and contexts.
You can think of the Context as our storage system. You can think of the Context as our storage system.
""" """
from copy import copy
from typing import TYPE_CHECKING, Optional from typing import TYPE_CHECKING, Optional
from django.template import Context from django.template import Context
@ -84,7 +85,7 @@ def capture_root_context(context: Context) -> None:
""" """
root_ctx_already_defined = _OUTER_CONTEXT_CONTEXT_KEY in context root_ctx_already_defined = _OUTER_CONTEXT_CONTEXT_KEY in context
if not root_ctx_already_defined: if not root_ctx_already_defined:
set_root_context(context, context.__copy__()) set_root_context(context, copy(context))
def set_slot_component_association(context: Context, slot_id: str, component_id: str) -> None: def set_slot_component_association(context: Context, slot_id: str, component_id: str) -> None:

View file

@ -1,5 +1,6 @@
import difflib import difflib
import json import json
from copy import copy
from typing import Dict, List, NamedTuple, Optional, Set, Type, Union from typing import Dict, List, NamedTuple, Optional, Set, Type, Union
from django.template import Context, Template from django.template import Context, Template
@ -145,7 +146,7 @@ class SlotNode(Node):
elif app_settings.SLOT_CONTEXT_BEHAVIOR == SlotContextBehavior.ISOLATED: elif app_settings.SLOT_CONTEXT_BEHAVIOR == SlotContextBehavior.ISOLATED:
return root_ctx return root_ctx
elif app_settings.SLOT_CONTEXT_BEHAVIOR == SlotContextBehavior.PREFER_ROOT: elif app_settings.SLOT_CONTEXT_BEHAVIOR == SlotContextBehavior.PREFER_ROOT:
new_context: Context = context.__copy__() new_context: Context = copy(context)
new_context.update(root_ctx.flatten()) new_context.update(root_ctx.flatten())
return new_context return new_context
else: else: