mirror of
https://github.com/django-components/django-components.git
synced 2025-08-09 08:48:00 +00:00
refactor: replace Sequence with List
This commit is contained in:
parent
1d0da559b4
commit
3e75db59ae
2 changed files with 8 additions and 8 deletions
|
@ -2,7 +2,7 @@ import inspect
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
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.core.exceptions import ImproperlyConfigured
|
||||||
from django.forms.widgets import Media, MediaDefiningClass
|
from django.forms.widgets import Media, MediaDefiningClass
|
||||||
|
@ -324,7 +324,7 @@ class ComponentNode(Node):
|
||||||
context_args: List[FilterExpression],
|
context_args: List[FilterExpression],
|
||||||
context_kwargs: Mapping[str, FilterExpression],
|
context_kwargs: Mapping[str, FilterExpression],
|
||||||
isolated_context: bool = False,
|
isolated_context: bool = False,
|
||||||
fill_nodes: Sequence[FillNode] = (),
|
fill_nodes: Optional[List[FillNode]] = None,
|
||||||
component_id: Optional[str] = None,
|
component_id: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.component_id = component_id or gen_id()
|
self.component_id = component_id or gen_id()
|
||||||
|
@ -332,7 +332,7 @@ class ComponentNode(Node):
|
||||||
self.context_args = context_args or []
|
self.context_args = context_args or []
|
||||||
self.context_kwargs = context_kwargs or {}
|
self.context_kwargs = context_kwargs or {}
|
||||||
self.isolated_context = isolated_context
|
self.isolated_context = isolated_context
|
||||||
self.fill_nodes = fill_nodes
|
self.fill_nodes = fill_nodes or []
|
||||||
self.nodelist = NodeList(fill_nodes)
|
self.nodelist = NodeList(fill_nodes)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import difflib
|
import difflib
|
||||||
import json
|
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 import Context, Template
|
||||||
from django.template.base import FilterExpression, Node, NodeList, Parser, TextNode
|
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(
|
def parse_slot_fill_nodes_from_component_nodelist(
|
||||||
component_nodelist: NodeList,
|
component_nodelist: NodeList,
|
||||||
ComponentNodeCls: Type[Node],
|
ComponentNodeCls: Type[Node],
|
||||||
) -> Sequence[FillNode]:
|
) -> List[FillNode]:
|
||||||
"""
|
"""
|
||||||
Given a component body (`django.template.NodeList`), find all slot fills,
|
Given a component body (`django.template.NodeList`), find all slot fills,
|
||||||
whether defined explicitly with `{% fill %}` or implicitly.
|
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"`
|
Then this function returns the nodes (`django.template.Node`) for `fill "first_fill"`
|
||||||
and `fill "second_fill"`.
|
and `fill "second_fill"`.
|
||||||
"""
|
"""
|
||||||
fill_nodes: Sequence[FillNode] = []
|
fill_nodes: List[FillNode] = []
|
||||||
if nodelist_has_content(component_nodelist):
|
if nodelist_has_content(component_nodelist):
|
||||||
for parse_fn in (
|
for parse_fn in (
|
||||||
_try_parse_as_default_fill,
|
_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(
|
def _try_parse_as_named_fill_tag_set(
|
||||||
nodelist: NodeList,
|
nodelist: NodeList,
|
||||||
ComponentNodeCls: Type[Node],
|
ComponentNodeCls: Type[Node],
|
||||||
) -> Sequence[FillNode]:
|
) -> List[FillNode]:
|
||||||
result = []
|
result = []
|
||||||
seen_name_fexps: Set[FilterExpression] = set()
|
seen_name_fexps: Set[FilterExpression] = set()
|
||||||
for node in nodelist:
|
for node in nodelist:
|
||||||
|
@ -329,7 +329,7 @@ def _try_parse_as_named_fill_tag_set(
|
||||||
def _try_parse_as_default_fill(
|
def _try_parse_as_default_fill(
|
||||||
nodelist: NodeList,
|
nodelist: NodeList,
|
||||||
ComponentNodeCls: Type[Node],
|
ComponentNodeCls: Type[Node],
|
||||||
) -> Sequence[FillNode]:
|
) -> List[FillNode]:
|
||||||
nodes_stack: List[Node] = list(nodelist)
|
nodes_stack: List[Node] = list(nodelist)
|
||||||
while nodes_stack:
|
while nodes_stack:
|
||||||
node = nodes_stack.pop()
|
node = nodes_stack.pop()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue