Skip to content

Commit 729e3d5

Browse files
committed
Fix a couple of code style issues
1 parent 0d45364 commit 729e3d5

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

dmoj/judge.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from http.server import HTTPServer
1010
from itertools import chain
1111

12-
from dmoj import graders, packet
12+
from dmoj import packet
1313
from dmoj.control import JudgeControlRequestHandler
1414
from dmoj.error import CompileError
1515
from dmoj.judgeenv import clear_problem_dirs_cache, env, get_supported_problems, startup_warnings
@@ -82,17 +82,8 @@ def update_problems(self):
8282
self.updater_signal.set()
8383

8484
def _block_and_grade(self, problem, language, source, short_circuit, report=print):
85-
if 'signature_grader' in problem.config:
86-
grader_class = graders.SignatureGrader
87-
elif 'interactive' in problem.config:
88-
grader_class = graders.BridgedInteractiveGrader
89-
elif 'custom_judge' in problem.config:
90-
grader_class = graders.CustomGrader
91-
else:
92-
grader_class = graders.StandardGrader
93-
9485
try:
95-
self.current_grader = grader_class(self, problem, language, utf8bytes(source))
86+
self.current_grader = problem.grader_class(self, problem, language, utf8bytes(source))
9687
except CompileError as compilation_error:
9788
error = compilation_error.args[0] or b'compiler exited abnormally'
9889

@@ -187,25 +178,23 @@ def grade_cases(self, grader, cases, short_circuit=False, is_short_circuiting=Fa
187178
if isinstance(case, BatchedTestCase):
188179
yield BatchBegin()
189180

190-
for batched_case in self.grade_cases(grader, case.batched_cases,
191-
short_circuit=case.config['short_circuit'],
192-
is_short_circuiting=is_short_circuiting):
181+
for batched_result in self.grade_cases(grader, case.batched_cases,
182+
short_circuit=case.config['short_circuit'],
183+
is_short_circuiting=is_short_circuiting):
193184
# A batched case just failed.
194185
# There are two cases where this means that we should completely short-circuit:
195186
# 1. If the batch was worth 0 points, to emulate the property of 0-point cases.
196187
# 2. If the short_circuit flag is true, see <https://github.com/DMOJ/judge/issues/341>.
197-
if (batched_case.result_flag & Result.WA) and \
188+
if (batched_result.result_flag & Result.WA) and \
198189
(short_circuit or case.kind in (TestCase.KIND_SAMPLE, TestCase.KIND_PRETEST)):
199190
is_short_circuiting = True
200-
yield batched_case
191+
yield batched_result
201192
yield BatchEnd()
202193
continue
203194

204195
# Stop grading if we're short circuiting
205196
if is_short_circuiting:
206-
result = Result(case)
207-
result.result_flag = Result.SC
208-
yield result
197+
yield Result(case, Result.SC)
209198
continue
210199

211200
result = grader.grade(case)

dmoj/problem.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ def _resolve_archive_files(self):
165165
return archive
166166
return None
167167

168+
@property
169+
def grader_class(self):
170+
from dmoj import graders
171+
172+
if 'signature_grader' in self.config:
173+
return graders.SignatureGrader
174+
elif 'interactive' in self.config:
175+
return graders.BridgedInteractiveGrader
176+
elif 'custom_judge' in self.config:
177+
return graders.CustomGrader
178+
else:
179+
return graders.StandardGrader
180+
168181

169182
class ProblemDataManager(dict):
170183
def __init__(self, problem_id, **kwargs):

dmoj/result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class Result:
2525
'IE': 'red',
2626
}
2727

28-
def __init__(self, case):
29-
self.result_flag = 0
28+
def __init__(self, case, result_flag=0):
29+
self.result_flag = result_flag
3030
self.execution_time = 0
3131
self.wall_clock_time = 0
3232
self.max_memory = 0

0 commit comments

Comments
 (0)