Skip to content

Commit a9e05a3

Browse files
fix linting
1 parent 8cc77c9 commit a9e05a3

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
@@ -583,7 +583,7 @@ def _get_object_forms(self) -> dict:
583583
return {}
584584

585585
result = {}
586-
for field_name, form_cls in self.form_classes.items():
586+
for field_name, form_cls in cast(dict, self.form_classes).items():
587587
obj = getattr(self, field_name, None)
588588
if obj is None:
589589
form_data = {}
@@ -714,17 +714,12 @@ def _validate_object_forms(self, model_names: list | None = None) -> None:
714714
# Re-map each sub-form error key to its dotted path, e.g.
715715
# "title" → "book.title" when field_name == "book".
716716
obj_form_errors = obj_form.errors.get_json_data(escape_html=True)
717-
dotted_errors = {
718-
f"{field_name}.{sub_key}": sub_errors
719-
for sub_key, sub_errors in obj_form_errors.items()
720-
}
717+
dotted_errors = {f"{field_name}.{sub_key}": sub_errors for sub_key, sub_errors in obj_form_errors.items()}
721718

722719
# Apply the same "persist only errors that are still invalid" logic.
723720
if self.errors:
724721
keys_to_remove = [
725-
key
726-
for key in self.errors
727-
if key.startswith(f"{field_name}.") and key not in dotted_errors
722+
key for key in self.errors if key.startswith(f"{field_name}.") and key not in dotted_errors
728723
]
729724
for key in keys_to_remove:
730725
self.errors.pop(key)

tests/components/test_component.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,7 @@ def test_form_classes_validate_all_fields_with_empty_object():
360360
"""
361361
from tests.views.fake_components import FakeFormClassesComponent
362362

363-
component = FakeFormClassesComponent(
364-
component_id="test_form_classes_validate_all", component_name="example"
365-
)
363+
component = FakeFormClassesComponent(component_id="test_form_classes_validate_all", component_name="example")
366364

367365
errors = component.validate()
368366

@@ -379,9 +377,7 @@ def test_form_classes_validate_model_names_filtered():
379377
"""
380378
from tests.views.fake_components import FakeFormClassesComponent
381379

382-
component = FakeFormClassesComponent(
383-
component_id="test_form_classes_filtered", component_name="example"
384-
)
380+
component = FakeFormClassesComponent(component_id="test_form_classes_filtered", component_name="example")
385381

386382
errors = component.validate(model_names=["book.title"])
387383

@@ -393,9 +389,7 @@ def test_form_classes_is_valid_with_empty_object():
393389
"""``is_valid()`` should return ``False`` when required object fields are missing."""
394390
from tests.views.fake_components import FakeFormClassesComponent
395391

396-
component = FakeFormClassesComponent(
397-
component_id="test_form_classes_is_valid_false", component_name="example"
398-
)
392+
component = FakeFormClassesComponent(component_id="test_form_classes_is_valid_false", component_name="example")
399393

400394
assert component.is_valid() is False
401395

@@ -405,13 +399,11 @@ def test_form_classes_validate_stale_errors_removed():
405399
Errors for an object field that has since become valid should be removed on
406400
the next ``validate()`` call.
407401
"""
408-
from example.books.models import Book
409-
410402
from tests.views.fake_components import FakeFormClassesComponent
411403

412-
component = FakeFormClassesComponent(
413-
component_id="test_form_classes_stale_errors", component_name="example"
414-
)
404+
from example.books.models import Book
405+
406+
component = FakeFormClassesComponent(component_id="test_form_classes_stale_errors", component_name="example")
415407

416408
# First validate with empty object — both fields should error.
417409
component.validate()
@@ -425,4 +417,3 @@ def test_form_classes_validate_stale_errors_removed():
425417

426418
assert "book.title" not in errors
427419
assert "book.date_published" not in errors
428-

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)