diff --git a/src/django_components/component.py b/src/django_components/component.py index 5be4903d..4debcc85 100644 --- a/src/django_components/component.py +++ b/src/django_components/component.py @@ -2,7 +2,7 @@ import inspect import os import sys from pathlib import Path -from typing import Any, ClassVar, Dict, List, Mapping, MutableMapping, Optional, Sequence, Tuple, Type, Union +from typing import Any, ClassVar, Dict, List, Mapping, MutableMapping, Optional, Tuple, Type, Union from django.core.exceptions import ImproperlyConfigured from django.forms.widgets import Media, MediaDefiningClass @@ -324,7 +324,7 @@ class ComponentNode(Node): context_args: List[FilterExpression], context_kwargs: Mapping[str, FilterExpression], isolated_context: bool = False, - fill_nodes: Sequence[FillNode] = (), + fill_nodes: Optional[List[FillNode]] = None, component_id: Optional[str] = None, ) -> None: self.component_id = component_id or gen_id() @@ -332,7 +332,7 @@ class ComponentNode(Node): self.context_args = context_args or [] self.context_kwargs = context_kwargs or {} self.isolated_context = isolated_context - self.fill_nodes = fill_nodes + self.fill_nodes = fill_nodes or [] self.nodelist = NodeList(fill_nodes) def __repr__(self) -> str: diff --git a/src/django_components/slots.py b/src/django_components/slots.py index bb83516d..a13bd219 100644 --- a/src/django_components/slots.py +++ b/src/django_components/slots.py @@ -1,6 +1,6 @@ import difflib import json -from typing import Dict, List, NamedTuple, Optional, Sequence, Set, Type, Union +from typing import Dict, List, NamedTuple, Optional, Set, Type, Union from django.template import Context, Template from django.template.base import FilterExpression, Node, NodeList, Parser, TextNode @@ -263,7 +263,7 @@ class IfSlotFilledNode(Node): def parse_slot_fill_nodes_from_component_nodelist( component_nodelist: NodeList, ComponentNodeCls: Type[Node], -) -> Sequence[FillNode]: +) -> List[FillNode]: """ Given a component body (`django.template.NodeList`), find all slot fills, whether defined explicitly with `{% fill %}` or implicitly. @@ -282,7 +282,7 @@ def parse_slot_fill_nodes_from_component_nodelist( Then this function returns the nodes (`django.template.Node`) for `fill "first_fill"` and `fill "second_fill"`. """ - fill_nodes: Sequence[FillNode] = [] + fill_nodes: List[FillNode] = [] if nodelist_has_content(component_nodelist): for parse_fn in ( _try_parse_as_default_fill, @@ -305,7 +305,7 @@ def parse_slot_fill_nodes_from_component_nodelist( def _try_parse_as_named_fill_tag_set( nodelist: NodeList, ComponentNodeCls: Type[Node], -) -> Sequence[FillNode]: +) -> List[FillNode]: result = [] seen_name_fexps: Set[FilterExpression] = set() for node in nodelist: @@ -329,7 +329,7 @@ def _try_parse_as_named_fill_tag_set( def _try_parse_as_default_fill( nodelist: NodeList, ComponentNodeCls: Type[Node], -) -> Sequence[FillNode]: +) -> List[FillNode]: nodes_stack: List[Node] = list(nodelist) while nodes_stack: node = nodes_stack.pop()