mirror of
https://github.com/django-components/django-components.git
synced 2025-07-24 08:43:43 +00:00
Fix #250 (3.6 failing) by removing postponed eval of type hints.
This commit is contained in:
parent
2848a3184d
commit
a47b007f67
4 changed files with 19 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
|||
from __future__ import annotations
|
||||
# from __future__ import annotations
|
||||
|
||||
import copy
|
||||
from typing import (
|
||||
|
@ -71,7 +71,7 @@ class Component(metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|||
|
||||
def __init__(self, component_name):
|
||||
self._component_name: str = component_name
|
||||
self._instance_fills: Optional[List[FillNode]] = None
|
||||
self._instance_fills: Optional[List["FillNode"]] = None
|
||||
self._outer_context: Optional[dict] = None
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
|
@ -100,7 +100,7 @@ class Component(metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|||
|
||||
def get_declared_slots(
|
||||
self, context: Context, template: Optional[Template] = None
|
||||
) -> List[SlotNode]:
|
||||
) -> List["SlotNode"]:
|
||||
if template is None:
|
||||
template = self.get_template(context)
|
||||
return list(
|
||||
|
@ -113,7 +113,7 @@ class Component(metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|||
template = get_template(template_name).template
|
||||
return template
|
||||
|
||||
def set_instance_fills(self, fills: Dict[str, FillNode]) -> None:
|
||||
def set_instance_fills(self, fills: Dict[str, "FillNode"]) -> None:
|
||||
self._instance_fills = fills
|
||||
|
||||
def set_outer_context(self, context):
|
||||
|
@ -145,12 +145,14 @@ class Component(metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|||
self,
|
||||
context,
|
||||
template: Template,
|
||||
fills: Optional[Dict[str, FillNode]] = None,
|
||||
fills: Optional[Dict[str, "FillNode"]] = None,
|
||||
) -> None:
|
||||
if fills is None:
|
||||
fills = self.instance_fills
|
||||
all_slots: List[SlotNode] = self.get_declared_slots(context, template)
|
||||
slots: Dict[str, SlotNode] = {}
|
||||
all_slots: List["SlotNode"] = self.get_declared_slots(
|
||||
context, template
|
||||
)
|
||||
slots: Dict[str, "SlotNode"] = {}
|
||||
# Each declared slot must have a unique name.
|
||||
for slot in all_slots:
|
||||
slot_name = slot.name
|
||||
|
@ -186,7 +188,7 @@ class Component(metaclass=SimplifiedInterfaceMediaDefiningClass):
|
|||
|
||||
def dfs_iter_slots_in_nodelist(
|
||||
nodelist: NodeList, template_name: str = None
|
||||
) -> Iterator[SlotNode]:
|
||||
) -> Iterator["SlotNode"]:
|
||||
from django_components.templatetags.component_tags import SlotNode
|
||||
|
||||
nodes: List[Node] = list(nodelist)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple
|
||||
|
||||
from django import template
|
||||
|
@ -154,7 +152,7 @@ class UserSlotVar:
|
|||
SlotNode.render() for implementation).
|
||||
"""
|
||||
|
||||
def __init__(self, slot: SlotNode, context: Context):
|
||||
def __init__(self, slot: "SlotNode", context: Context):
|
||||
self._slot = slot
|
||||
self._context = context
|
||||
|
||||
|
@ -245,9 +243,9 @@ def do_slot(parser, token):
|
|||
class FillNode(Node):
|
||||
def __init__(
|
||||
self,
|
||||
name_var: NameVariable,
|
||||
name_var: "NameVariable",
|
||||
nodelist: NodeList,
|
||||
alias_var: Optional[NameVariable] = None,
|
||||
alias_var: Optional["NameVariable"] = None,
|
||||
):
|
||||
self.name_var = name_var
|
||||
self.nodelist = nodelist
|
||||
|
@ -307,7 +305,7 @@ class ComponentNode(Node):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
name_var: NameVariable,
|
||||
name_var: "NameVariable",
|
||||
context_args,
|
||||
context_kwargs,
|
||||
isolated_context=False,
|
||||
|
@ -521,7 +519,7 @@ def do_if_filled_block(parser, token):
|
|||
|
||||
def parse_if_filled_bits(
|
||||
bits: List[str],
|
||||
) -> Tuple[Optional[NameVariable], Optional[bool]]:
|
||||
) -> Tuple[Optional["NameVariable"], Optional[bool]]:
|
||||
tag, args = bits[0], bits[1:]
|
||||
if tag in ("else_filled", "endif_filled"):
|
||||
if len(args) != 0:
|
||||
|
@ -551,7 +549,7 @@ class IfSlotFilledNode(Node):
|
|||
def __init__(
|
||||
self,
|
||||
branches: List[
|
||||
Tuple[Optional[NameVariable], NodeList, Optional[bool]]
|
||||
Tuple[Optional["NameVariable"], NodeList, Optional[bool]]
|
||||
],
|
||||
):
|
||||
# [(<slot name var | None (= condition)>, nodelist, <is_positive>)]
|
||||
|
|
|
@ -8,4 +8,5 @@ exclude =
|
|||
settings.py
|
||||
env
|
||||
.env
|
||||
.venv
|
||||
.tox
|
3
setup.py
3
setup.py
|
@ -11,7 +11,8 @@ setup(
|
|||
version=VERSION,
|
||||
description="A way to create simple reusable template components in Django.",
|
||||
long_description=open(
|
||||
os.path.join(os.path.dirname(__file__), "README.md")
|
||||
os.path.join(os.path.dirname(__file__), "README.md"),
|
||||
encoding="utf8"
|
||||
).read(),
|
||||
long_description_content_type="text/markdown",
|
||||
author="Emil Stenström",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue