refactor: make it optional having to specify parent class of Args, Kwargs, Slots, etc (#1466)

This commit is contained in:
Juro Oravec 2025-10-21 15:30:08 +02:00 committed by GitHub
parent 0aeb96fa40
commit c37628dea0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 661 additions and 299 deletions

View file

@ -5,7 +5,7 @@ For tests focusing on the `component` tag, see `test_templatetags_component.py`
import os
import re
from typing import Any, List, Literal, NamedTuple, Optional
from typing import Any, List, Literal, Optional
import pytest
from django.conf import settings
@ -591,23 +591,23 @@ class TestComponentRenderAPI:
class TestComponent(Component):
template = ""
class Args(NamedTuple):
class Args:
variable: int
another: str
class Kwargs(NamedTuple):
class Kwargs:
variable: str
another: int
class Slots(NamedTuple):
class Slots:
my_slot: SlotInput
def get_template_data(self, args, kwargs, slots, context):
nonlocal called
called = True
assert self.args == TestComponent.Args(123, "str")
assert self.kwargs == TestComponent.Kwargs(variable="test", another=1)
assert self.args == TestComponent.Args(123, "str") # type: ignore[call-arg]
assert self.kwargs == TestComponent.Kwargs(variable="test", another=1) # type: ignore[call-arg]
assert isinstance(self.slots, TestComponent.Slots)
assert isinstance(self.slots.my_slot, Slot)
assert self.slots.my_slot() == "MY_SLOT"
@ -789,15 +789,15 @@ class TestComponentTemplateVars:
def test_args_kwargs_slots__simple_typed(self):
class TestComponent(Component):
class Args(NamedTuple):
class Args:
variable: int
another: str
class Kwargs(NamedTuple):
class Kwargs:
variable: str
another: int
class Slots(NamedTuple):
class Slots:
my_slot: SlotInput
template: types.django_html = """
@ -898,15 +898,15 @@ class TestComponentTemplateVars:
"""
class TestComponent(Component):
class Args(NamedTuple):
class Args:
variable: int
another: str
class Kwargs(NamedTuple):
class Kwargs:
variable: str
another: int
class Slots(NamedTuple):
class Slots:
my_slot: SlotInput
template: types.django_html = """