Skip to content

Commit 28bd785

Browse files
committed
utils.coerce - warning are opt-in
1 parent 2c5c8cd commit 28bd785

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

aocd/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def answer_a(self, val: AnswerValue) -> None:
329329
to the server if necessary.
330330
"""
331331
if not isinstance(val, str):
332-
val = coerce(val)
332+
val = coerce(val, warn=True)
333333
if getattr(self, "answer_a", None) == val:
334334
return
335335
self._submit(value=val, part="a")
@@ -362,7 +362,7 @@ def answer_b(self, val: AnswerValue) -> None:
362362
to the server if necessary.
363363
"""
364364
if not isinstance(val, str):
365-
val = coerce(val)
365+
val = coerce(val, warn=True)
366366
if getattr(self, "answer_b", None) == val:
367367
return
368368
self._submit(value=val, part="b")
@@ -422,7 +422,7 @@ def _submit(self, value, part, reopen=True, quiet=False, precheck=True):
422422
if value in NON_ANSWER:
423423
raise AocdError(f"cowardly refusing to submit non-answer: {value!r}")
424424
if not isinstance(value, str):
425-
value = coerce(value)
425+
value = coerce(value, warn=True)
426426
part = str(part).replace("1", "a").replace("2", "b").lower()
427427
if part not in {"a", "b"}:
428428
raise AocdError('part must be "a" or "b"')

aocd/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def _get_soup(html):
272272
return bs4.BeautifulSoup(html, "html.parser")
273273

274274

275-
def coerce(val: t.Any, warn: bool = True) -> str:
275+
def coerce(val: t.Any, warn: bool = False) -> str:
276276
"""
277277
Convert answer `val` into a string suitable for HTTP submission.
278278
Technically adventofcode.com will only accept strings as answers,

tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_atomic_write_file(aocd_data_dir):
9898
],
9999
)
100100
def test_type_coercions(v_raw, v_expected, len_logs, caplog):
101-
v_actual = coerce(v_raw)
101+
v_actual = coerce(v_raw, warn=True)
102102
assert v_actual == v_expected, f"{type(v_raw)} {v_raw})"
103103
assert len(caplog.records) == len_logs
104104

0 commit comments

Comments
 (0)