Skip to content

Commit 637e8f0

Browse files
fix linting
1 parent 4412148 commit 637e8f0

File tree

4 files changed

+9
-25
lines changed

4 files changed

+9
-25
lines changed

src/django_unicorn/components/unicorn_view.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def _get_object_forms(self) -> dict:
626626
return {}
627627

628628
result = {}
629-
for field_name, form_cls in self.form_classes.items():
629+
for field_name, form_cls in cast(dict, self.form_classes).items():
630630
obj = getattr(self, field_name, None)
631631
if obj is None:
632632
form_data = {}
@@ -757,17 +757,12 @@ def _validate_object_forms(self, model_names: list | None = None) -> None:
757757
# Re-map each sub-form error key to its dotted path, e.g.
758758
# "title" → "book.title" when field_name == "book".
759759
obj_form_errors = obj_form.errors.get_json_data(escape_html=True)
760-
dotted_errors = {
761-
f"{field_name}.{sub_key}": sub_errors
762-
for sub_key, sub_errors in obj_form_errors.items()
763-
}
760+
dotted_errors = {f"{field_name}.{sub_key}": sub_errors for sub_key, sub_errors in obj_form_errors.items()}
764761

765762
# Apply the same "persist only errors that are still invalid" logic.
766763
if self.errors:
767764
keys_to_remove = [
768-
key
769-
for key in self.errors
770-
if key.startswith(f"{field_name}.") and key not in dotted_errors
765+
key for key in self.errors if key.startswith(f"{field_name}.") and key not in dotted_errors
771766
]
772767
for key in keys_to_remove:
773768
self.errors.pop(key)

tests/components/test_component.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,7 @@ def test_form_classes_validate_all_fields_with_empty_object():
541541
"""
542542
from tests.views.fake_components import FakeFormClassesComponent
543543

544-
component = FakeFormClassesComponent(
545-
component_id="test_form_classes_validate_all", component_name="example"
546-
)
544+
component = FakeFormClassesComponent(component_id="test_form_classes_validate_all", component_name="example")
547545

548546
errors = component.validate()
549547

@@ -560,9 +558,7 @@ def test_form_classes_validate_model_names_filtered():
560558
"""
561559
from tests.views.fake_components import FakeFormClassesComponent
562560

563-
component = FakeFormClassesComponent(
564-
component_id="test_form_classes_filtered", component_name="example"
565-
)
561+
component = FakeFormClassesComponent(component_id="test_form_classes_filtered", component_name="example")
566562

567563
errors = component.validate(model_names=["book.title"])
568564

@@ -574,9 +570,7 @@ def test_form_classes_is_valid_with_empty_object():
574570
"""``is_valid()`` should return ``False`` when required object fields are missing."""
575571
from tests.views.fake_components import FakeFormClassesComponent
576572

577-
component = FakeFormClassesComponent(
578-
component_id="test_form_classes_is_valid_false", component_name="example"
579-
)
573+
component = FakeFormClassesComponent(component_id="test_form_classes_is_valid_false", component_name="example")
580574

581575
assert component.is_valid() is False
582576

@@ -586,13 +580,11 @@ def test_form_classes_validate_stale_errors_removed():
586580
Errors for an object field that has since become valid should be removed on
587581
the next ``validate()`` call.
588582
"""
589-
from example.books.models import Book
590-
591583
from tests.views.fake_components import FakeFormClassesComponent
592584

593-
component = FakeFormClassesComponent(
594-
component_id="test_form_classes_stale_errors", component_name="example"
595-
)
585+
from example.books.models import Book
586+
587+
component = FakeFormClassesComponent(component_id="test_form_classes_stale_errors", component_name="example")
596588

597589
# First validate with empty object — both fields should error.
598590
component.validate()
@@ -606,4 +598,3 @@ def test_form_classes_validate_stale_errors_removed():
606598

607599
assert "book.title" not in errors
608600
assert "book.date_published" not in errors
609-

tests/views/fake_components.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,3 @@ def __init__(self, **kwargs):
229229

230230
def save(self):
231231
self.validate()
232-

tests/views/message/test_form_classes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import pytest
1010
from tests.views.message.utils import post_and_get_response
1111

12-
1312
COMPONENT_URL = "/message/tests.views.fake_components.FakeFormClassesComponent"
1413

1514

0 commit comments

Comments
 (0)