Skip to content

Commit 0721ea7

Browse files
mzuennimpsijm
andauthored
#102 More types in util.py (#423)
* more types * Update bin/util.py Co-authored-by: Maarten Sijm <9739541+mpsijm@users.noreply.github.com> * add Popen type * fix * add Named Type --------- Co-authored-by: Maarten Sijm <9739541+mpsijm@users.noreply.github.com>
1 parent 3292e6c commit 0721ea7

File tree

7 files changed

+274
-160
lines changed

7 files changed

+274
-160
lines changed

bin/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
# fmt: on
101101

102102

103-
def set_default_args():
103+
def set_default_args() -> None:
104104
# Set default argument values.
105105
for arg in ARGS_LIST:
106106
if not hasattr(args, arg):

bin/contest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import config
2+
13
from pathlib import Path
24

35
from util import *

bin/generate.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def callback(program):
128128

129129
# Return the form of the command used for caching.
130130
# This is independent of {name} and the actual run_command.
131-
def cache_command(self, seed=None):
131+
def cache_command(self, seed=None) -> str:
132132
command_string = self.command_string
133133
if seed:
134134
command_string = self.SEED_REGEX.sub(str(seed), command_string)
@@ -137,6 +137,7 @@ def cache_command(self, seed=None):
137137
def hash(self, seed=None):
138138
list = []
139139
if self.program is not None:
140+
assert self.program.hash is not None
140141
list.append(self.program.hash)
141142
list.append(self.cache_command(seed))
142143
return combine_hashes(list)
@@ -605,13 +606,13 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent, coun
605606
return
606607

607608
# build ordered list of hashes we want to consider
608-
self.hash = [hashes[ext] for ext in config.KNOWN_TESTCASE_EXTENSIONS if ext in hashes]
609+
hs = [hashes[ext] for ext in config.KNOWN_TESTCASE_EXTENSIONS if ext in hashes]
609610

610611
# combine hashes
611-
if len(self.hash) == 1:
612-
self.hash = self.hash[0]
612+
if len(hs) == 1:
613+
self.hash = hs[0]
613614
else:
614-
self.hash = combine_hashes(self.hash)
615+
self.hash = combine_hashes(hs)
615616

616617
if self.hash in generator_config.rules_cache:
617618
self.copy_of = generator_config.rules_cache[self.hash]
@@ -1081,13 +1082,13 @@ def add_testdata_to_cache():
10811082
hashes[ext] = hash_file(target_infile.with_suffix(ext))
10821083

10831084
# build ordered list of hashes we want to consider
1084-
test_hash = [hashes[ext] for ext in extensions if ext in hashes]
1085+
hs = [hashes[ext] for ext in extensions if ext in hashes]
10851086

10861087
# combine hashes
1087-
if len(test_hash) == 1:
1088-
test_hash = test_hash[0]
1088+
if len(hs) == 1:
1089+
test_hash = hs[0]
10891090
else:
1090-
test_hash = combine_hashes(test_hash)
1091+
test_hash = combine_hashes(hs)
10911092

10921093
# check for duplicates
10931094
if test_hash not in generator_config.generated_testdata:

bin/program.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(
145145
problem.path.resolve() / self.subdir
146146
)
147147
self.short_path = relpath
148-
self.name = str(relpath)
148+
self.name: str = str(relpath)
149149
self.tmpdir = problem.tmpdir / self.subdir / relpath
150150
except ValueError:
151151
self.short_path = Path(path.name)

bin/run.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, problem: "problem.Problem", submission, testcase):
3030
self.problem = problem
3131
self.submission = submission
3232
self.testcase = testcase
33-
self.name = self.testcase.name
33+
self.name: str = self.testcase.name
3434
self.result = None
3535

3636
self.tmpdir = (
@@ -228,6 +228,7 @@ def _validate_output(self, bar):
228228
ret.err = ""
229229
if judgeerror.is_file():
230230
ret.err = judgeerror.read_text(errors="replace")
231+
assert ret.err is not None
231232
if len(ret.err) == 0 and judgemessage.is_file():
232233
ret.err = judgemessage.read_text(errors="replace")
233234
if ret.err:

bin/stats.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,6 @@ def get_submissions_row(display_name, names):
379379
error("git not found!")
380380
return
381381

382-
if not exec_command(["git", "rev-parse", "--is-inside-work-tree"]).out.startswith("true"):
383-
error("not inside git")
384-
return
385-
386382
def git(*args):
387383
res = exec_command(
388384
["git", *args],
@@ -392,6 +388,10 @@ def git(*args):
392388
)
393389
return res.out if res else ""
394390

391+
if not git("rev-parse", "--is-inside-work-tree").startswith("true"):
392+
error("not inside git")
393+
return
394+
395395
print("-" * len(header), file=sys.stderr)
396396
testcases = [len(generate.testcases(p)) for p in problems]
397397
testcases += get_stats(testcases)

0 commit comments

Comments
 (0)