Skip to content

Commit 05e34a1

Browse files
committed
fix(python): restore language autocomplete via split run_code overloads
Pyright collapses Literal[...] | str to str, so split the language parameter into separate overloads: known literals vs arbitrary str, matching the prior pattern that preserves IDE suggestions.
1 parent e1e7a5f commit 05e34a1

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

python/e2b_code_interpreter/code_interpreter_async.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,44 @@ def _client(self) -> AsyncClient:
6868
async def run_code(
6969
self,
7070
code: str,
71-
language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None,
71+
language: Optional[
72+
Literal["python", "javascript", "typescript", "r", "java", "bash"]
73+
] = None,
74+
on_stdout: Optional[OutputHandlerWithAsync[OutputMessage]] = None,
75+
on_stderr: Optional[OutputHandlerWithAsync[OutputMessage]] = None,
76+
on_result: Optional[OutputHandlerWithAsync[Result]] = None,
77+
on_error: Optional[OutputHandlerWithAsync[ExecutionError]] = None,
78+
envs: Optional[Dict[str, str]] = None,
79+
timeout: Optional[float] = None,
80+
request_timeout: Optional[float] = None,
81+
) -> Execution:
82+
"""
83+
Runs the code for the specified language.
84+
85+
Specify the `language` or `context` option to run the code as a different language or in a different `Context`.
86+
If no language is specified, Python is used.
87+
88+
You can reference previously defined variables, imports, and functions in the code.
89+
90+
:param code: Code to execute
91+
:param language: Language to use for code execution. If not defined, the default Python context is used.
92+
:param on_stdout: Callback for stdout messages
93+
:param on_stderr: Callback for stderr messages
94+
:param on_result: Callback for the `Result` object
95+
:param on_error: Callback for the `ExecutionError` object
96+
:param envs: Custom environment variables
97+
:param timeout: Timeout for the code execution in **seconds**
98+
:param request_timeout: Timeout for the request in **seconds**
99+
100+
:return: `Execution` result object
101+
"""
102+
...
103+
104+
@overload
105+
async def run_code(
106+
self,
107+
code: str,
108+
language: Optional[str] = None,
72109
on_stdout: Optional[OutputHandlerWithAsync[OutputMessage]] = None,
73110
on_stderr: Optional[OutputHandlerWithAsync[OutputMessage]] = None,
74111
on_result: Optional[OutputHandlerWithAsync[Result]] = None,

python/e2b_code_interpreter/code_interpreter_sync.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,44 @@ def _client(self) -> Client:
6565
def run_code(
6666
self,
6767
code: str,
68-
language: Union[Literal["python", "javascript", "typescript", "r", "java", "bash"], str, None] = None,
68+
language: Optional[
69+
Literal["python", "javascript", "typescript", "r", "java", "bash"]
70+
] = None,
71+
on_stdout: Optional[OutputHandler[OutputMessage]] = None,
72+
on_stderr: Optional[OutputHandler[OutputMessage]] = None,
73+
on_result: Optional[OutputHandler[Result]] = None,
74+
on_error: Optional[OutputHandler[ExecutionError]] = None,
75+
envs: Optional[Dict[str, str]] = None,
76+
timeout: Optional[float] = None,
77+
request_timeout: Optional[float] = None,
78+
) -> Execution:
79+
"""
80+
Runs the code for the specified language.
81+
82+
Specify the `language` or `context` option to run the code as a different language or in a different `Context`.
83+
If no language is specified, Python is used.
84+
85+
You can reference previously defined variables, imports, and functions in the code.
86+
87+
:param code: Code to execute
88+
:param language: Language to use for code execution. If not defined, the default Python context is used.
89+
:param on_stdout: Callback for stdout messages
90+
:param on_stderr: Callback for stderr messages
91+
:param on_result: Callback for the `Result` object
92+
:param on_error: Callback for the `ExecutionError` object
93+
:param envs: Custom environment variables
94+
:param timeout: Timeout for the code execution in **seconds**
95+
:param request_timeout: Timeout for the request in **seconds**
96+
97+
:return: `Execution` result object
98+
"""
99+
...
100+
101+
@overload
102+
def run_code(
103+
self,
104+
code: str,
105+
language: Optional[str] = None,
69106
on_stdout: Optional[OutputHandler[OutputMessage]] = None,
70107
on_stderr: Optional[OutputHandler[OutputMessage]] = None,
71108
on_result: Optional[OutputHandler[Result]] = None,

0 commit comments

Comments
 (0)