Skip to content

Commit db5187e

Browse files
committed
#102 mypy: enable error codes truthy-bool and truthy-iterable
1 parent 4a70f02 commit db5187e

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ repos:
3030
args:
3131
- --check-untyped-defs
3232
- --exclude=test
33+
- --enable-error-code=truthy-bool
34+
- --enable-error-code=truthy-iterable
3335
- --no-incremental # Fixes ruamel.yaml, see https://stackoverflow.com/a/65223004
3436
- --python-version=3.10
3537
- --scripts-are-modules

bin/interactive.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,18 +460,18 @@ def close_io(stream: Optional[IO[bytes]]) -> None:
460460
if stream:
461461
stream.close()
462462

463-
if validator:
463+
if validator is not None:
464464
validator.wait()
465465
close_io(validator.stdin)
466466
close_io(validator.stdout)
467467
close_io(validator.stderr)
468-
if team_tee:
468+
if team_tee is not None:
469469
team_tee.wait()
470470
close_io(team_tee.stdin)
471-
if val_tee:
471+
if val_tee is not None:
472472
val_tee.wait()
473473
close_io(val_tee.stdout)
474-
if submission:
474+
if submission is not None:
475475
submission.wait()
476476
close_io(submission.stderr)
477477

bin/run.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def _get_expected_verdicts(self) -> list[Verdict]:
356356
expected_verdicts.sort()
357357
return expected_verdicts or [Verdict.ACCEPTED]
358358

359-
# Run submission on in_path, writing stdout to out_path or stdout if out_path is None.
359+
# Run submission on in_path, writing stdout to out_path.
360360
# args is used by SubmissionInvocation to pass on additional arguments.
361361
# Returns ExecResult
362362
# The `generator_timeout` argument is used when a submission is run as a solution when
@@ -374,10 +374,7 @@ def run(
374374
# Just for safety reasons, change the cwd.
375375
if cwd is None:
376376
cwd = self.tmpdir
377-
with (
378-
in_path.open("rb") as in_file,
379-
out_path.open("wb") if out_path else nullcontext(None) as out_file,
380-
):
377+
with in_path.open("rb") as in_file, out_path.open("wb") as out_file:
381378
# Print stderr to terminal is stdout is None, otherwise return its value.
382379
result = self._exec_command(
383380
[*self.run_command, *args],
@@ -719,7 +716,7 @@ def test_interactive(self) -> None:
719716
finally:
720717
os.close(r)
721718
os.close(w)
722-
if writer:
719+
if writer is not None:
723720
writer.kill()
724721
writer.wait()
725722
bar.done()

bin/skel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
copytree_and_substitute,
1717
error,
1818
exec_command,
19+
ExecStatus,
1920
fatal,
2021
generate_problem_uuid,
2122
has_ryaml,
@@ -299,7 +300,7 @@ def git(*args: str | Path) -> str:
299300
preexec_fn=False,
300301
timeout=None,
301302
)
302-
return res.out if res and res.out else ""
303+
return res.out if res.status == ExecStatus.ACCEPTED and res.out else ""
303304

304305
if not git("rev-parse", "--is-inside-work-tree").startswith("true"):
305306
error("not inside git")

bin/stats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import program
1414
import validate
1515
from problem import Problem
16-
from util import eprint, error, exec_command, glob, log, warn
16+
from util import eprint, error, exec_command, ExecStatus, glob, log, warn
1717

1818
Selector = (
1919
str | Callable[[Problem], int | float] | list[str] | list[Callable[[set[Path]], set[str]]]
@@ -430,7 +430,7 @@ def git(*args: str | Path) -> str:
430430
preexec_fn=False,
431431
timeout=None,
432432
)
433-
return res.out if res and res.out else ""
433+
return res.out if res.status == ExecStatus.ACCEPTED and res.out else ""
434434

435435
if not git("rev-parse", "--is-inside-work-tree").startswith("true"):
436436
error("not inside git")

bin/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ def interrupt_handler(sig: Any, frame: Any) -> None:
14491449
def maybe_crop(s: str) -> str:
14501450
return crop_output(s) if crop else s
14511451

1452-
ok = exec_code_map(process.returncode)
1452+
status = exec_code_map(process.returncode)
14531453
err = maybe_crop(stderr.decode("utf-8", "replace")) if stderr is not None else None
14541454
out = maybe_crop(stdout.decode("utf-8", "replace")) if stdout is not None else None
14551455

@@ -1462,7 +1462,7 @@ def maybe_crop(s: str) -> str:
14621462
else:
14631463
duration = tend - tstart
14641464

1465-
return ExecResult(process.returncode, ok, duration, timeout_expired, err, out)
1465+
return ExecResult(process.returncode, status, duration, timeout_expired, err, out)
14661466

14671467

14681468
def inc_label(label: str) -> str:

0 commit comments

Comments
 (0)