Skip to content

Commit cd3549b

Browse files
oschwaldclaude
andcommitted
Replace Any with object for unused kwargs
Use object rather than Any for the discarded **_ keyword-argument parameters. object is the correct type for values that are accepted but never used, and it satisfies Ruff's ANN401 rule, so the per-file ANN401 ignores can be removed. The two constructors that forward **kwargs on to the geoip2 parent constructors keep Any (with an inline noqa), since object is not assignable to the parent's typed parameters. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 2ba74a3 commit cd3549b

3 files changed

Lines changed: 24 additions & 25 deletions

File tree

CLAUDE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ def __init__(
105105
field_name: str | None = None,
106106
is_flag: bool | None = None,
107107
# ... other keyword-only parameters
108-
**_: Any, # ignore unknown keys
108+
**_: object, # ignore unknown keys
109109
) -> None:
110110
```
111111

112112
Key points:
113113
- Use `*` to enforce keyword-only arguments
114-
- Accept `**_: Any` to ignore unknown keys from the API (forward compatibility)
114+
- Accept `**_: object` to ignore unknown keys from the API (forward compatibility)
115115
- Use `| None = None` for optional parameters
116116
- Boolean fields can be `None` if not provided by API
117117

@@ -252,7 +252,7 @@ def test_email(self) -> None:
252252
*,
253253
new_field: str | None = None,
254254
# ... other params
255-
**_: Any,
255+
**_: object,
256256
) -> None:
257257
```
258258

@@ -281,7 +281,7 @@ When creating a new model class:
281281
2. **Follow the constructor pattern** from existing models
282282
3. **Use type hints** for all attributes
283283
4. **Use keyword-only arguments** with `*` separator
284-
5. **Accept `**_: Any`** to ignore unknown API keys
284+
5. **Accept `**_: object`** to ignore unknown API keys
285285
6. **Provide comprehensive docstrings** for all attributes
286286
7. **Add corresponding tests** with full coverage
287287

@@ -376,7 +376,7 @@ Adding required parameters breaks existing code.
376376
- Always add new parameters as optional with defaults
377377
- Use keyword-only arguments (after `*`)
378378
- Never add required positional parameters to existing constructors
379-
- Use `**_: Any` to silently accept unknown parameters from API
379+
- Use `**_: object` to silently accept unknown parameters from API
380380

381381
## Code Style Requirements
382382

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ ignorelist = ["id"]
9292

9393
[tool.ruff.lint.per-file-ignores]
9494
"docs/*" = ["ALL"]
95-
"src/minfraud/models.py" = ["ANN401", "PLR0913"]
96-
"src/minfraud/webservice.py" = ["ANN401"]
95+
"src/minfraud/models.py" = ["PLR0913"]
9796
"tests/*" = ["ANN201", "D"]
9897

9998
[tool.tox]

src/minfraud/models.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class GeoIP2Location(geoip2.records.Location):
100100
`RFC 3339 <https://datatracker.ietf.org/doc/html/rfc3339>`_. For instance, the
101101
local time in Boston might be returned as 2015-04-27T19:17:24-04:00."""
102102

103-
def __init__(self, *args: Any, **kwargs: Any) -> None:
103+
def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401
104104
"""Initialize a GeoIP2Location instance."""
105105
self.local_time = kwargs.get("local_time")
106106
super().__init__(*args, **kwargs)
@@ -135,7 +135,7 @@ def __init__(
135135
location: dict[str, Any] | None = None,
136136
risk: float | None = None,
137137
risk_reasons: list[dict[str, Any]] | None = None,
138-
**kwargs: Any,
138+
**kwargs: Any, # noqa: ANN401
139139
) -> None:
140140
"""Initialize an IPAddress instance."""
141141
# For raw attribute
@@ -161,7 +161,7 @@ class ScoreIPAddress(_Serializable):
161161
"""This field contains the risk associated with the IP address. The value
162162
ranges from 0.01 to 99. A higher score indicates a higher risk."""
163163

164-
def __init__(self, *, risk: float | None = None, **_: Any) -> None:
164+
def __init__(self, *, risk: float | None = None, **_: object) -> None:
165165
"""Initialize a ScoreIPAddress instance."""
166166
self.risk = risk
167167

@@ -197,7 +197,7 @@ def __init__(
197197
matches_provided_name: bool | None = None,
198198
phone_number: str | None = None,
199199
matches_provided_phone_number: bool | None = None,
200-
**_: Any,
200+
**_: object,
201201
) -> None:
202202
"""Initialize an Issuer instance."""
203203
self.name = name
@@ -239,7 +239,7 @@ def __init__(
239239
id: str | None = None,
240240
last_seen: str | None = None,
241241
local_time: str | None = None,
242-
**_: Any,
242+
**_: object,
243243
) -> None:
244244
"""Initialize a Device instance."""
245245
self.confidence = confidence
@@ -277,7 +277,7 @@ def __init__(
277277
action: str | None = None,
278278
reason: str | None = None,
279279
rule_label: str | None = None,
280-
**_: Any,
280+
**_: object,
281281
) -> None:
282282
"""Initialize a Disposition instance."""
283283
self.action = action
@@ -310,7 +310,7 @@ def __init__(
310310
status: str | None = None,
311311
last_visited_on: str | None = None,
312312
has_redirect: bool | None = None,
313-
**_: Any,
313+
**_: object,
314314
) -> None:
315315
"""Initialize an EmailDomainVisit instance."""
316316
self.status = status
@@ -354,7 +354,7 @@ def __init__(
354354
risk: float | None = None,
355355
volume: float | None = None,
356356
visit: dict[str, Any] | None = None,
357-
**_: Any,
357+
**_: object,
358358
) -> None:
359359
"""Initialize an EmailDomain instance."""
360360
self.first_seen = first_seen
@@ -498,7 +498,7 @@ def __init__(
498498
longitude: float | None = None,
499499
distance_to_ip_location: int | None = None,
500500
is_in_ip_country: bool | None = None,
501-
**_: Any,
501+
**_: object,
502502
) -> None:
503503
"""Initialize a BillingAddress instance."""
504504
self.is_postal_in_city = is_postal_in_city
@@ -553,7 +553,7 @@ def __init__(
553553
is_in_ip_country: bool | None = None,
554554
is_high_risk: bool | None = None,
555555
distance_to_billing_address: int | None = None,
556-
**_: Any,
556+
**_: object,
557557
) -> None:
558558
"""Initialize a ShippingAddress instance."""
559559
self.is_postal_in_city = is_postal_in_city
@@ -604,7 +604,7 @@ def __init__(
604604
matches_postal: bool | None = None,
605605
network_operator: str | None = None,
606606
number_type: str | None = None,
607-
**_: Any,
607+
**_: object,
608608
) -> None:
609609
"""Initialize a Phone instance."""
610610
self.country = country
@@ -639,7 +639,7 @@ def __init__(
639639
code: str | None = None,
640640
warning: str | None = None,
641641
input_pointer: str | None = None,
642-
**_: Any,
642+
**_: object,
643643
) -> None:
644644
"""Initialize a ServiceWarning instance."""
645645
self.code = code
@@ -783,7 +783,7 @@ def __init__(
783783
shipping_address: float | None = None,
784784
shipping_address_distance_to_ip_location: float | None = None,
785785
time_of_day: float | None = None,
786-
**_: Any,
786+
**_: object,
787787
) -> None:
788788
"""Initialize a Subscores instance."""
789789
self.avs_result = avs_result
@@ -897,7 +897,7 @@ def __init__(
897897
*,
898898
code: str | None = None,
899899
reason: str | None = None,
900-
**_: Any,
900+
**_: object,
901901
) -> None:
902902
"""Initialize a Reason instance."""
903903
self.code = code
@@ -922,7 +922,7 @@ def __init__(
922922
*,
923923
multiplier: float,
924924
reasons: list[dict[str, Any]] | None = None,
925-
**_: Any,
925+
**_: object,
926926
) -> None:
927927
"""Initialize a RiskScoreReason instance."""
928928
self.multiplier = multiplier
@@ -1030,7 +1030,7 @@ def __init__(
10301030
subscores: dict[str, Any] | None = None,
10311031
warnings: list[dict[str, Any]] | None = None,
10321032
risk_score_reasons: list[dict[str, Any]] | None = None,
1033-
**_: Any,
1033+
**_: object,
10341034
) -> None:
10351035
"""Initialize a Factors instance."""
10361036
self.billing_address = BillingAddress(**(billing_address or {}))
@@ -1136,7 +1136,7 @@ def __init__(
11361136
shipping_address: dict[str, Any] | None = None,
11371137
shipping_phone: dict[str, Any] | None = None,
11381138
warnings: list[dict[str, Any]] | None = None,
1139-
**_: Any,
1139+
**_: object,
11401140
) -> None:
11411141
"""Initialize an Insights instance."""
11421142
self.billing_address = BillingAddress(**(billing_address or {}))
@@ -1201,7 +1201,7 @@ def __init__(
12011201
queries_remaining: int,
12021202
risk_score: float,
12031203
warnings: list[dict[str, Any]] | None = None,
1204-
**_: Any,
1204+
**_: object,
12051205
) -> None:
12061206
"""Initialize a Score instance."""
12071207
self.disposition = Disposition(**(disposition or {}))

0 commit comments

Comments
 (0)