Skip to content

Commit bea2f25

Browse files
fix linting
1 parent 8f39b91 commit bea2f25

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/django_unicorn/components/unicorn_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def __init__(self, component_args: list | None = None, **kwargs):
232232
# Apply Meta.component_key as a class-level default when the template
233233
# tag has not provided a key (i.e. self.component_key is still empty).
234234
if not self.component_key and hasattr(self, "Meta") and hasattr(self.Meta, "component_key"):
235-
self.component_key = self.Meta.component_key
235+
self.component_key = cast(str, self.Meta.component_key)
236236

237237
self._set_default_template_name()
238238
self._set_caches()

tests/components/test_component.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from tests.views.fake_components import (
66
FakeAuthenticationComponent,
77
FakeValidationComponent,
8+
FakeValidationForm,
89
)
910

1011
from django_unicorn.components import UnicornView
@@ -377,7 +378,7 @@ class TestComponent(UnicornView):
377378
class Meta:
378379
template_name = 123
379380

380-
with pytest.raises(AssertionError, match="Meta.template_name should be a str"):
381+
with pytest.raises(AssertionError, match=r"Meta\.template_name should be a str"):
381382
TestComponent(component_id="test_meta_template_name_invalid", component_name="test")
382383

383384

@@ -398,9 +399,9 @@ class Meta:
398399
def test_meta_template_html_invalid_type():
399400
class TestComponent(UnicornView):
400401
class Meta:
401-
template_html = ["<div>oops</div>"]
402+
template_html = 123
402403

403-
with pytest.raises(AssertionError, match="Meta.template_html should be a str"):
404+
with pytest.raises(AssertionError, match=r"Meta\.template_html should be a str"):
404405
TestComponent(component_id="test_meta_template_html_invalid", component_name="test")
405406

406407

@@ -414,9 +415,7 @@ class TestComponent(UnicornView):
414415
class Meta:
415416
component_key = "default-key"
416417

417-
component = TestComponent(
418-
component_id="test_meta_component_key", component_name="test", component_key=""
419-
)
418+
component = TestComponent(component_id="test_meta_component_key", component_name="test", component_key="")
420419
assert component.component_key == "default-key"
421420

422421

@@ -442,16 +441,14 @@ class TestComponent(UnicornView):
442441
class Meta:
443442
component_key = 42
444443

445-
with pytest.raises(AssertionError, match="Meta.component_key should be a str"):
444+
with pytest.raises(AssertionError, match=r"Meta\.component_key should be a str"):
446445
TestComponent(component_id="test_meta_component_key_invalid", component_name="test")
447446

448447

449448
# ── Meta: form_class ──────────────────────────────────────────────────────────
450449

451450

452451
def test_meta_form_class_validates():
453-
from tests.views.fake_components import FakeValidationForm
454-
455452
class TestComponent(UnicornView):
456453
template_name = "unicorn/test.html"
457454
text = "hi"
@@ -470,11 +467,6 @@ class Meta:
470467

471468
def test_meta_form_class_not_in_frontend_context():
472469
"""form_class must never appear in the component's public attributes."""
473-
from tests.views.fake_components import FakeValidationComponent
474470

475-
component = FakeValidationComponent(
476-
component_id="test_form_class_not_in_context", component_name="example"
477-
)
471+
component = FakeValidationComponent(component_id="test_form_class_not_in_context", component_name="example")
478472
assert "form_class" not in component._attributes()
479-
480-

0 commit comments

Comments
 (0)