Skip to content

Commit 3d31a59

Browse files
Hermanzdosilovic/kwargs (#5)
* Make Python default language * Add kwargs in sync_execute and async_execute * Make Python default language for Submission. language_id is positional or keyword argument with default value. Fix formatting in error message. --------- Co-authored-by: Filip Karlo Došilović <filipk.dosilovic@gmail.com>
1 parent fc3d91d commit 3d31a59

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

examples/0004_hello_world.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import judge0
2+
3+
result = judge0.run(source_code="print('Hello Judge0')")
4+
print(result.stdout)

src/judge0/api.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def resolve_client(
5050
return JUDGE0_IMPLICIT_EXTRA_CE_CLIENT
5151

5252
raise RuntimeError(
53-
"Failed to resolve the client from submissions argument."
54-
"None of the implicit clients supports all languages from the submissions."
53+
"Failed to resolve the client from submissions argument. "
54+
"None of the implicit clients supports all languages from the submissions. "
5555
"Please explicitly provide the client argument."
5656
)
5757

@@ -103,7 +103,17 @@ def async_execute(
103103
*,
104104
client: Optional[Union[Client, Flavor]] = None,
105105
submissions: Optional[Union[Submission, list[Submission]]] = None,
106+
source_code: Optional[str] = None,
107+
**kwargs,
106108
) -> Union[Submission, list[Submission]]:
109+
if submissions is not None and source_code is not None:
110+
raise ValueError(
111+
"source_code argument cannot be provided if submissions argument is provided."
112+
)
113+
114+
if source_code is not None:
115+
submissions = Submission(source_code=source_code, **kwargs)
116+
107117
# Check the edge cases if client is not provided.
108118
if client is None:
109119
if submissions is None:
@@ -127,7 +137,17 @@ def sync_execute(
127137
*,
128138
client: Optional[Union[Client, Flavor]] = None,
129139
submissions: Optional[Union[Submission, list[Submission]]] = None,
140+
source_code: Optional[str] = None,
141+
**kwargs,
130142
) -> Union[Submission, list[Submission]]:
143+
if submissions is not None and source_code is not None:
144+
raise ValueError(
145+
"source_code argument cannot be provided if submissions argument is provided."
146+
)
147+
148+
if source_code is not None:
149+
submissions = Submission(source_code=source_code, **kwargs)
150+
131151
# Check the edge cases if client is not provided.
132152
if client is None:
133153
if submissions is None:

src/judge0/submission.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Submission:
5454
def __init__(
5555
self,
5656
source_code: str,
57-
language_id: Union[Language, int],
57+
language_id: Union[Language, int] = Language.PYTHON,
5858
*,
5959
additional_files=None,
6060
compiler_options=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