diff --git a/django_components/component.py b/django_components/component.py index 5aef8d59..aeb51c4d 100644 --- a/django_components/component.py +++ b/django_components/component.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import copy from typing import ( TYPE_CHECKING, @@ -71,7 +69,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 +98,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 +111,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 +143,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 +186,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) diff --git a/django_components/templatetags/component_tags.py b/django_components/templatetags/component_tags.py index c8cee67f..0ac8959e 100644 --- a/django_components/templatetags/component_tags.py +++ b/django_components/templatetags/component_tags.py @@ -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]] ], ): # [(, nodelist, )] diff --git a/requirements-dev.txt b/requirements-dev.txt index dd1b5b2c..47566c2d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -18,7 +18,7 @@ colorama==0.4.6 # via tox distlib==0.3.6 # via virtualenv -django==4.1.7 +django==4.2 # via -r requirements-dev.in filelock==3.10.7 # via diff --git a/setup.cfg b/setup.cfg index c03e366f..11ad2955 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,4 +8,5 @@ exclude = settings.py env .env + .venv .tox \ No newline at end of file diff --git a/setup.py b/setup.py index c005457e..210db953 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import os from setuptools import find_packages, setup -VERSION = "0.26.2" +VERSION = "0.26.3" setup( name="django_components", @@ -11,7 +11,7 @@ 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", diff --git a/tox.ini b/tox.ini index 069210ae..a430759e 100644 --- a/tox.ini +++ b/tox.ini @@ -13,11 +13,11 @@ envlist = [gh-actions] python = - 3.6: py36 - 3.7: py37 - 3.8: py38 - 3.9: py39 - 3.10: py310, flake8, isort + 3.6: py36-django{32} + 3.7: py37-django{32} + 3.8: py38-django{32,40} + 3.9: py39-django{32,40} + 3.10: py310-django{40}, flake8, isort fail_on_no_env = True [testenv]