Skip to content

Commit a95d1cc

Browse files
committed
Add check for None values in set_attributes.
1 parent 67c089c commit a95d1cc

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/judge0/submission.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
RESPONSE_FIELDS = ENCODED_RESPONSE_FIELDS | EXTRA_RESPONSE_FIELDS
4747
FIELDS = REQUEST_FIELDS | RESPONSE_FIELDS
4848
SKIP_FIELDS = {"language_id", "language", "status_id"}
49+
DATETIME_FIELDS = {"created_at", "finished_at"}
50+
FLOATING_POINT_FIELDS = {
51+
"cpu_time_limit",
52+
"cpu_extra_time",
53+
"time",
54+
"wall_time",
55+
"wall_time_limit",
56+
}
4957

5058

5159
class Submission:
@@ -129,15 +137,9 @@ def set_attributes(self, attributes):
129137
value = decode(value) if value else None
130138
elif attr == "status":
131139
value = Status(value["id"])
132-
elif attr in ("created_at", "finished_at"):
140+
elif attr in DATETIME_FIELDS and value is not None:
133141
value = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%fZ")
134-
elif attr in (
135-
"wall_time",
136-
"wall_time_limit",
137-
"cpu_extra_time",
138-
"cpu_time_limit",
139-
"time",
140-
):
142+
elif attr in FLOATING_POINT_FIELDS and value is not None:
141143
value = float(value)
142144

143145
setattr(self, attr, value)
@@ -149,6 +151,7 @@ def to_dict(self, client: "Client") -> dict:
149151
"language_id": client.get_language_id(self.language),
150152
}
151153

154+
# TODO: Iterate over ENCODED_REQUEST_FIELDS.
152155
if self.stdin is not None:
153156
body["stdin"] = encode(self.stdin)
154157
if self.expected_output is not None:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy