Skip to content

Commit f4cd8ab

Browse files
committed
Minor submit client cleanup.
- docstrings are triple double quotes, not single quotes - added some more return types - process exit codes are non-negative
1 parent 14c43e4 commit f4cd8ab

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

submit/submit

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def confirm(message: str) -> bool:
5050
return answer == 'y'
5151

5252

53-
def warn_user(msg: str):
53+
def warn_user(msg: str) -> None:
5454
global num_warnings
5555
num_warnings += 1
5656
if args.quiet:
@@ -67,11 +67,11 @@ def usage(msg: str) -> NoReturn:
6767

6868
def error(msg: str) -> NoReturn:
6969
logging.error(msg)
70-
exit(-1)
70+
exit(1)
7171

7272

73-
def print_if_json(text: str):
74-
'''Print the text if it is valid JSON, and ignore otherwise'''
73+
def print_if_json(text: str) -> None:
74+
"""Print the text if it is valid JSON, and ignore otherwise"""
7575
try:
7676
data = json.loads(text)
7777
print(json.dumps(data, indent=2))
@@ -80,11 +80,11 @@ def print_if_json(text: str):
8080

8181

8282
def read_contests() -> list:
83-
'''Read all contests from the API.
83+
"""Read all contests from the API.
8484
8585
Returns:
8686
The contests or None if an error occurred.
87-
'''
87+
"""
8888

8989
try:
9090
data = do_api_request('contests')
@@ -111,11 +111,11 @@ def read_contests() -> list:
111111

112112

113113
def read_languages() -> list:
114-
'''Read all languages for the current contest from the API.
114+
"""Read all languages for the current contest from the API.
115115
116116
Returns:
117117
The languages or None if an error occurred.
118-
'''
118+
"""
119119

120120
try:
121121
endpoint = 'contests/' + my_contest['id'] + '/languages'
@@ -153,11 +153,11 @@ def read_languages() -> list:
153153

154154

155155
def read_problems() -> list:
156-
'''Read all problems for the current contest from the API.
156+
"""Read all problems for the current contest from the API.
157157
158158
Returns:
159159
The problems or None if an error occurred.
160-
'''
160+
"""
161161

162162
try:
163163
endpoint = 'contests/' + my_contest['id'] + '/problems'
@@ -187,7 +187,7 @@ def read_problems() -> list:
187187

188188

189189
def do_api_request(endpoint: str, data=None, files=None):
190-
'''Perform an API call to the given endpoint and return its data.
190+
"""Perform an API call to the given endpoint and return its data.
191191
192192
Parameters:
193193
endpoint (str): the endpoint to call
@@ -199,7 +199,7 @@ def do_api_request(endpoint: str, data=None, files=None):
199199
200200
Raises:
201201
RuntimeError when the response is not JSON or the HTTP status code is non 2xx.
202-
'''
202+
"""
203203

204204
if not baseurl:
205205
raise RuntimeError('No baseurl set')
@@ -249,8 +249,8 @@ def kotlin_base_entry_point(filebase: str) -> str:
249249
return filebase
250250

251251

252-
def get_epilog():
253-
'''Get the epilog for the help text.'''
252+
def get_epilog() -> str:
253+
"""Get the epilog for the help text."""
254254

255255
contests_part_one = None
256256
contests_part_two = None
@@ -323,8 +323,8 @@ Submit multiple files (the problem and language are taken from the first):
323323
return "\n\n".join(part for part in epilog_parts if part)
324324

325325

326-
def do_api_print():
327-
'''Submit to the API for printing with the given data.'''
326+
def do_api_print() -> None:
327+
"""Submit to the API for printing with the given data."""
328328

329329
if len(filenames) != 1:
330330
error('You can only print a single file')
@@ -353,8 +353,8 @@ def do_api_print():
353353
print(f"DOMjudge reported a printing error: {result['output']}")
354354

355355

356-
def do_api_submit():
357-
'''Submit to the API with the given data.'''
356+
def do_api_submit() -> None:
357+
"""Submit to the API with the given data."""
358358

359359
data = {
360360
'problem': my_problem['id'],

0 commit comments

Comments
 (0)