5050class CodeBox :
5151 def __new__ (
5252 cls ,
53- session_id : str | None = None ,
54- api_key : str | t .Literal ["local" , "docker" ] | None = None ,
55- factory_id : str | t .Literal ["default" ] | None = None ,
53+ session_id : t . Optional [ str ] = None ,
54+ api_key : t . Optional [ t . Union [ str , t .Literal ["local" , "docker" ]]] = None ,
55+ factory_id : t . Optional [ t . Union [ str , t .Literal ["default" ]]] = None ,
5656 ) -> "CodeBox" :
5757 """
5858 Creates a CodeBox session
@@ -68,9 +68,9 @@ def __new__(
6868
6969 def __init__ (
7070 self ,
71- session_id : str | None = None ,
72- api_key : str | t .Literal ["local" , "docker" ] | None = None ,
73- factory_id : str | t .Literal ["default" ] | None = None ,
71+ session_id : t . Optional [ str ] = None ,
72+ api_key : t . Optional [ t . Union [ str , t .Literal ["local" , "docker" ]]] = None ,
73+ factory_id : t . Optional [ t . Union [ str , t .Literal ["default" ]]] = None ,
7474 ** _ : bool ,
7575 ) -> None :
7676 self .session_id = session_id or "local"
@@ -81,37 +81,37 @@ def __init__(
8181
8282 def exec (
8383 self ,
84- code : str | os .PathLike ,
84+ code : t . Union [ str , os .PathLike ] ,
8585 kernel : t .Literal ["ipython" , "bash" ] = "ipython" ,
86- timeout : float | None = None ,
87- cwd : str | None = None ,
86+ timeout : t . Optional [ float ] = None ,
87+ cwd : t . Optional [ str ] = None ,
8888 ) -> "ExecResult" :
8989 """Execute code inside the CodeBox instance"""
9090 return flatten_exec_result (self .stream_exec (code , kernel , timeout , cwd ))
9191
9292 def stream_exec (
9393 self ,
94- code : str | os .PathLike ,
94+ code : t . Union [ str , os .PathLike ] ,
9595 kernel : t .Literal ["ipython" , "bash" ] = "ipython" ,
96- timeout : float | None = None ,
97- cwd : str | None = None ,
96+ timeout : t . Optional [ float ] = None ,
97+ cwd : t . Optional [ str ] = None ,
9898 ) -> t .Generator ["ExecChunk" , None , None ]:
9999 """Executes the code and streams the result."""
100100 raise NotImplementedError ("Abstract method, please use a subclass." )
101101
102102 def upload (
103103 self ,
104104 remote_file_path : str ,
105- content : t .BinaryIO | bytes | str ,
106- timeout : float | None = None ,
105+ content : t .Union [ t . BinaryIO , bytes , str ] ,
106+ timeout : t . Optional [ float ] = None ,
107107 ) -> "RemoteFile" :
108108 """Upload a file to the CodeBox instance"""
109109 raise NotImplementedError ("Abstract method, please use a subclass." )
110110
111111 def stream_download (
112112 self ,
113113 remote_file_path : str ,
114- timeout : float | None = None ,
114+ timeout : t . Optional [ float ] = None ,
115115 ) -> t .Generator [bytes , None , None ]:
116116 """Download a file as open BinaryIO. Make sure to close the file after use."""
117117 raise NotImplementedError ("Abstract method, please use a subclass." )
@@ -120,10 +120,10 @@ def stream_download(
120120
121121 async def aexec (
122122 self ,
123- code : str | os .PathLike ,
123+ code : t . Union [ str , os .PathLike ] ,
124124 kernel : t .Literal ["ipython" , "bash" ] = "ipython" ,
125- timeout : float | None = None ,
126- cwd : str | None = None ,
125+ timeout : t . Optional [ float ] = None ,
126+ cwd : t . Optional [ str ] = None ,
127127 ) -> "ExecResult" :
128128 """Async Execute python code inside the CodeBox instance"""
129129 return await async_flatten_exec_result (
@@ -132,34 +132,34 @@ async def aexec(
132132
133133 def astream_exec (
134134 self ,
135- code : str | os .PathLike ,
135+ code : t . Union [ str , os .PathLike ] ,
136136 kernel : t .Literal ["ipython" , "bash" ] = "ipython" ,
137- timeout : float | None = None ,
138- cwd : str | None = None ,
137+ timeout : t . Optional [ float ] = None ,
138+ cwd : t . Optional [ str ] = None ,
139139 ) -> t .AsyncGenerator ["ExecChunk" , None ]:
140140 """Async Stream Chunks of Execute python code inside the CodeBox instance"""
141141 raise NotImplementedError ("Abstract method, please use a subclass." )
142142
143143 async def aupload (
144144 self ,
145145 remote_file_path : str ,
146- content : t .BinaryIO | bytes | str ,
147- timeout : float | None = None ,
146+ content : t .Union [ t . BinaryIO , bytes , str ] ,
147+ timeout : t . Optional [ float ] = None ,
148148 ) -> "RemoteFile" :
149149 """Async Upload a file to the CodeBox instance"""
150150 raise NotImplementedError ("Abstract method, please use a subclass." )
151151
152152 async def adownload (
153153 self ,
154154 remote_file_path : str ,
155- timeout : float | None = None ,
155+ timeout : t . Optional [ float ] = None ,
156156 ) -> "RemoteFile" :
157157 return [f for f in (await self .alist_files ()) if f .path in remote_file_path ][0 ]
158158
159159 def astream_download (
160160 self ,
161161 remote_file_path : str ,
162- timeout : float | None = None ,
162+ timeout : t . Optional [ float ] = None ,
163163 ) -> t .AsyncGenerator [bytes , None ]:
164164 """Async Download a file as BinaryIO. Make sure to close the file after use."""
165165 raise NotImplementedError ("Abstract method, please use a subclass." )
@@ -242,7 +242,7 @@ async def ping(cb: CodeBox, d: int) -> None:
242242 # SYNCIFY
243243
244244 def download (
245- self , remote_file_path : str , timeout : float | None = None
245+ self , remote_file_path : str , timeout : t . Optional [ float ] = None
246246 ) -> "RemoteFile" :
247247 return syncify (self .adownload )(remote_file_path , timeout )
248248
@@ -288,7 +288,7 @@ async def astop(self) -> t.Literal["stopped"]:
288288 @deprecated (
289289 "The `.run` method is deprecated. Use `.exec` instead." ,
290290 )
291- async def arun (self , code : str | os .PathLike ) -> "CodeBoxOutput" :
291+ async def arun (self , code : t . Union [ str , os .PathLike ] ) -> "CodeBoxOutput" :
292292 from .types import CodeBoxOutput
293293
294294 exec_result = await self .aexec (code , kernel = "ipython" )
@@ -321,7 +321,7 @@ def stop(self) -> t.Literal["stopped"]:
321321 @deprecated (
322322 "The `.run` method is deprecated. Use `.exec` instead." ,
323323 )
324- def run (self , code : str | os .PathLike ) -> "CodeBoxOutput" :
324+ def run (self , code : t . Union [ str , os .PathLike ] ) -> "CodeBoxOutput" :
325325 return syncify (self .arun )(code )
326326
327327 @deprecated (
0 commit comments