Skip to content

Commit af7a6de

Browse files
MartinCastroAlvarezmartin-castro-laminr-aiclaude
authored
chore(types): tighten list_filter helpers (no more typing.Any in params) (#537)
The four ANN401 sites in api/filters.py were the last `Any` parameter types in production code. `_entry_spec(entry)` accepts a list_filter element whose shape Django doesn't constrain — `object` matches the defensive isinstance-check pattern more honestly than Any. The three `_spec_for_*(field)` helpers take a concrete Django model `Field` (which is already imported), so type them that way. Co-authored-by: Martin Castro Laminrs <mcastro@laminr.ai> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 905eca4 commit af7a6de

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

django_admin_react/api/filters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
_FK_FILTER_MAX_OPTIONS = 25
6161

6262

63-
def _entry_spec(entry: Any) -> tuple[str | None, type | None]:
63+
def _entry_spec(entry: object) -> tuple[str | None, type | None]:
6464
"""Normalize a `list_filter` entry to ``(field_name, filter_cls)``.
6565
6666
Django accepts entries in three forms:
@@ -124,15 +124,15 @@ def _resolve_field_path(model: type[Model], path: str) -> Field | None:
124124
return field
125125

126126

127-
def _spec_for_boolean(field_name: str, field: Any) -> dict[str, Any]:
127+
def _spec_for_boolean(field_name: str, field: Field) -> dict[str, Any]:
128128
return {
129129
"name": field_name,
130130
"label": str(getattr(field, "verbose_name", field_name) or field_name).strip(),
131131
"type": "boolean",
132132
}
133133

134134

135-
def _spec_for_choices(field_name: str, field: Any) -> dict[str, Any]:
135+
def _spec_for_choices(field_name: str, field: Field) -> dict[str, Any]:
136136
raw_choices = list(getattr(field, "choices", None) or [])
137137
return {
138138
"name": field_name,
@@ -213,7 +213,7 @@ def _spec_for_fk(
213213
return payload
214214

215215

216-
def _spec_for_date(field_name: str, field: Any) -> dict[str, Any]:
216+
def _spec_for_date(field_name: str, field: Field) -> dict[str, Any]:
217217
return {
218218
"name": field_name,
219219
"label": str(getattr(field, "verbose_name", field_name) or field_name).strip(),

0 commit comments

Comments
 (0)