diff --git a/src/django_components/component_media.py b/src/django_components/component_media.py
index 07e4dc0b..f47f74f6 100644
--- a/src/django_components/component_media.py
+++ b/src/django_components/component_media.py
@@ -758,20 +758,23 @@ def _map_media_filepaths(media: Type[ComponentMediaInput], map_fn: Callable[[Seq
def _is_media_filepath(filepath: Any) -> bool:
+ # Case callable
if callable(filepath):
return True
- if (
- isinstance(filepath, SafeData)
- or hasattr(filepath, "__html__")
- or isinstance(filepath, (Path, os.PathLike))
- or hasattr(filepath, "__fspath__")
- ):
+ # Case SafeString
+ if isinstance(filepath, SafeData) or hasattr(filepath, "__html__"):
return True
+ # Case PathLike
+ if isinstance(filepath, (Path, os.PathLike)) or hasattr(filepath, "__fspath__"):
+ return True
+
+ # Case bytes
if isinstance(filepath, bytes):
return True
+ # Case str
return isinstance(filepath, str)
diff --git a/src/django_components/extension.py b/src/django_components/extension.py
index bc9b6d4a..eeba0a2a 100644
--- a/src/django_components/extension.py
+++ b/src/django_components/extension.py
@@ -1043,7 +1043,7 @@ class ExtensionManager:
if component_ext_subclass:
bases_list.insert(0, component_ext_subclass)
- bases: tuple[Type, ...] = tuple(bases_list)
+ bases: Tuple[Type, ...] = tuple(bases_list)
# Allow component-level extension class to access the owner `Component` class that via
# `component_cls`.
diff --git a/src/django_components/extensions/cache.py b/src/django_components/extensions/cache.py
index 8d16872a..aec33bb3 100644
--- a/src/django_components/extensions/cache.py
+++ b/src/django_components/extensions/cache.py
@@ -176,7 +176,7 @@ class CacheExtension(ComponentExtension):
ComponentConfig = ComponentCache
def __init__(self, *_args: Any, **_kwargs: Any) -> None:
- self.render_id_to_cache_key: dict[str, str] = {}
+ self.render_id_to_cache_key: Dict[str, str] = {}
def on_component_input(self, ctx: OnComponentInputContext) -> Optional[Any]:
cache_instance = ctx.component.cache
diff --git a/src/django_components/extensions/debug_highlight.py b/src/django_components/extensions/debug_highlight.py
index 704111cf..52ea0e16 100644
--- a/src/django_components/extensions/debug_highlight.py
+++ b/src/django_components/extensions/debug_highlight.py
@@ -36,13 +36,13 @@ def apply_component_highlight(highlight_type: Literal["component", "slot"], outp
output = f"""
-
+
{output}
"""
diff --git a/src/django_components/provide.py b/src/django_components/provide.py
index afcac681..9df43aec 100644
--- a/src/django_components/provide.py
+++ b/src/django_components/provide.py
@@ -157,7 +157,8 @@ def set_provided_context_var(
# We turn the kwargs into a NamedTuple so that the object that's "provided"
# is immutable. This ensures that the data returned from `inject` will always
# have all the keys that were passed to the `provide` tag.
- tuple_cls = NamedTuple("DepInject", provided_kwargs.keys()) # type: ignore[misc]
+ fields = [(field, Any) for field in provided_kwargs]
+ tuple_cls = NamedTuple("DepInject", fields) # type: ignore[misc]
payload = tuple_cls(**provided_kwargs)
# Instead of storing the provided data on the Context object, we store it
diff --git a/tests/test_component_cache.py b/tests/test_component_cache.py
index 835dad8f..69ccb221 100644
--- a/tests/test_component_cache.py
+++ b/tests/test_component_cache.py
@@ -338,7 +338,7 @@ class TestComponentCache:
return {"input": kwargs["input"]}
with pytest.raises(
- ValueError,
+ TypeError,
match=re.escape(
"Cannot hash slot 'content' of component 'TestComponent' - Slot functions are unhashable.",
),
diff --git a/tests/test_component_media.py b/tests/test_component_media.py
index e2fe174c..96c73f1c 100644
--- a/tests/test_component_media.py
+++ b/tests/test_component_media.py
@@ -4,7 +4,7 @@ import re
import sys
from pathlib import Path
from textwrap import dedent
-from typing import Optional
+from typing import List, Optional
import pytest
from django.core.exceptions import ImproperlyConfigured
@@ -344,7 +344,7 @@ class TestComponentMedia:
def test_media_custom_render_js(self):
class MyMedia(Media):
def render_js(self):
- tags: list[str] = []
+ tags: List[str] = []
for path in self._js: # type: ignore[attr-defined]
abs_path = self.absolute_path(path) # type: ignore[attr-defined]
tags.append(f'')
@@ -370,7 +370,7 @@ class TestComponentMedia:
def test_media_custom_render_css(self):
class MyMedia(Media):
def render_css(self):
- tags: list[str] = []
+ tags: List[str] = []
media = sorted(self._css) # type: ignore[attr-defined]
for medium in media:
for path in self._css[medium]: # type: ignore[attr-defined]
@@ -789,7 +789,7 @@ class TestMediaStaticfiles:
class MyMedia(Media):
def render_js(self):
- tags: list[str] = []
+ tags: List[str] = []
for path in self._js: # type: ignore[attr-defined]
abs_path = self.absolute_path(path) # type: ignore[attr-defined]
tags.append(f'')
@@ -849,7 +849,7 @@ class TestMediaStaticfiles:
class MyMedia(Media):
def render_js(self):
- tags: list[str] = []
+ tags: List[str] = []
for path in self._js: # type: ignore[attr-defined]
abs_path = self.absolute_path(path) # type: ignore[attr-defined]
tags.append(f'')
diff --git a/tests/test_component_view.py b/tests/test_component_view.py
index 10cbeb3f..d35e866a 100644
--- a/tests/test_component_view.py
+++ b/tests/test_component_view.py
@@ -201,7 +201,10 @@ class TestComponentAsView:
client = CustomClient(urlpatterns=[path("test/", view)])
response = client.get("/test/")
assert response.status_code == 200
- assert b'
' in response.content
+ assertInHTML(
+ '
',
+ response.content.decode(),
+ )
def test_replace_slot_in_view(self):
class MockComponentSlot(Component):
diff --git a/tests/test_slots.py b/tests/test_slots.py
index eb07c4f3..9b9a3333 100644
--- a/tests/test_slots.py
+++ b/tests/test_slots.py
@@ -121,7 +121,7 @@ class TestSlot:
slot: Slot = Slot(lambda _ctx: "SLOT_FN")
with pytest.raises(
- ValueError,
+ TypeError,
match=re.escape("Slot received another Slot instance as `contents`"),
):
Slot(slot)
diff --git a/tests/test_templatetags_slot_fill.py b/tests/test_templatetags_slot_fill.py
index 39ffbfaa..9965f67e 100644
--- a/tests/test_templatetags_slot_fill.py
+++ b/tests/test_templatetags_slot_fill.py
@@ -2434,7 +2434,7 @@ class TestSlotInput:
@djc_test(parametrize=PARAMETRIZE_CONTEXT_BEHAVIOR)
def test_slots_normalized_as_slot_instances(self, components_settings):
- seen_slots: dict[str, Slot] = {}
+ seen_slots: Dict[str, Slot] = {}
@register("test")
class SlottedComponent(Component):