Skip to content

Commit f7fb511

Browse files
fix linting
1 parent f5b20f9 commit f7fb511

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
@@ -603,7 +603,7 @@ def _get_object_forms(self) -> dict:
603603
return {}
604604

605605
result = {}
606-
for field_name, form_cls in self.form_classes.items():
606+
for field_name, form_cls in cast(dict, self.form_classes).items():
607607
obj = getattr(self, field_name, None)
608608
if obj is None:
609609
form_data = {}
@@ -734,17 +734,12 @@ def _validate_object_forms(self, model_names: list | None = None) -> None:
734734
# Re-map each sub-form error key to its dotted path, e.g.
735735
# "title" → "book.title" when field_name == "book".
736736
obj_form_errors = obj_form.errors.get_json_data(escape_html=True)
737-
dotted_errors = {
738-
f"{field_name}.{sub_key}": sub_errors
739-
for sub_key, sub_errors in obj_form_errors.items()
740-
}
737+
dotted_errors = {f"{field_name}.{sub_key}": sub_errors for sub_key, sub_errors in obj_form_errors.items()}
741738

742739
# Apply the same "persist only errors that are still invalid" logic.
743740
if self.errors:
744741
keys_to_remove = [
745-
key
746-
for key in self.errors
747-
if key.startswith(f"{field_name}.") and key not in dotted_errors
742+
key for key in self.errors if key.startswith(f"{field_name}.") and key not in dotted_errors
748743
]
749744
for key in keys_to_remove:
750745
self.errors.pop(key)

tests/components/test_component.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,7 @@ def test_form_classes_validate_all_fields_with_empty_object():
416416
"""
417417
from tests.views.fake_components import FakeFormClassesComponent
418418

419-
component = FakeFormClassesComponent(
420-
component_id="test_form_classes_validate_all", component_name="example"
421-
)
419+
component = FakeFormClassesComponent(component_id="test_form_classes_validate_all", component_name="example")
422420

423421
errors = component.validate()
424422

@@ -435,9 +433,7 @@ def test_form_classes_validate_model_names_filtered():
435433
"""
436434
from tests.views.fake_components import FakeFormClassesComponent
437435

438-
component = FakeFormClassesComponent(
439-
component_id="test_form_classes_filtered", component_name="example"
440-
)
436+
component = FakeFormClassesComponent(component_id="test_form_classes_filtered", component_name="example")
441437

442438
errors = component.validate(model_names=["book.title"])
443439

@@ -449,9 +445,7 @@ def test_form_classes_is_valid_with_empty_object():
449445
"""``is_valid()`` should return ``False`` when required object fields are missing."""
450446
from tests.views.fake_components import FakeFormClassesComponent
451447

452-
component = FakeFormClassesComponent(
453-
component_id="test_form_classes_is_valid_false", component_name="example"
454-
)
448+
component = FakeFormClassesComponent(component_id="test_form_classes_is_valid_false", component_name="example")
455449

456450
assert component.is_valid() is False
457451

@@ -461,13 +455,11 @@ def test_form_classes_validate_stale_errors_removed():
461455
Errors for an object field that has since become valid should be removed on
462456
the next ``validate()`` call.
463457
"""
464-
from example.books.models import Book
465-
466458
from tests.views.fake_components import FakeFormClassesComponent
467459

468-
component = FakeFormClassesComponent(
469-
component_id="test_form_classes_stale_errors", component_name="example"
470-
)
460+
from example.books.models import Book
461+
462+
component = FakeFormClassesComponent(component_id="test_form_classes_stale_errors", component_name="example")
471463

472464
# First validate with empty object — both fields should error.
473465
component.validate()
@@ -481,4 +473,3 @@ def test_form_classes_validate_stale_errors_removed():
481473

482474
assert "book.title" not in errors
483475
assert "book.date_published" not in errors
484-

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)