22
33from __future__ import annotations
44
5- from typing import TYPE_CHECKING , List , Optional , overload
5+ from typing import TYPE_CHECKING , List , Literal , Optional , overload
66
77from typing_extensions import TypedDict , Unpack
88
@@ -104,7 +104,11 @@ class _DestroyAttrs(TypedDict, total=False):
104104 dry_run : bool
105105 """If `True`, the cache will not be destroyed, only the operation will be simulated."""
106106
107- def destroy (self , ** kwargs : Unpack [SystemRuntimeCache ._DestroyAttrs ]) -> Task :
107+ @overload
108+ def destroy (self , * , dry_run : Literal [True ]) -> None : ...
109+ @overload
110+ def destroy (self , * , dry_run : Literal [False ] = False ) -> Task : ...
111+ def destroy (self , ** kwargs ) -> Task | None :
108112 """
109113 Remove a content runtime package cache.
110114
@@ -115,6 +119,11 @@ def destroy(self, **kwargs: Unpack[SystemRuntimeCache._DestroyAttrs]) -> Task:
115119 dry_run : bool, optional
116120 If `True`, the cache will not be destroyed, only the operation will be simulated.
117121
122+ Returns
123+ -------
124+ Task | None
125+ The task object if the operation was successful. If `dry_run=True`, `None` is returned.
126+
118127 Examples
119128 --------
120129 ```python
@@ -126,7 +135,7 @@ def destroy(self, **kwargs: Unpack[SystemRuntimeCache._DestroyAttrs]) -> Task:
126135 first_runtime_cache = runtime_caches[0]
127136
128137 # Remove the cache
129- task = first_runtime_cache.destroy(dry_run=True )
138+ task = first_runtime_cache.destroy(dry_run=False )
130139
131140 # Wait for the task to finish
132141 task.wait_for()
@@ -138,7 +147,7 @@ def destroy(self, **kwargs: Unpack[SystemRuntimeCache._DestroyAttrs]) -> Task:
138147
139148 task_id = response .json ().get ("task_id" )
140149 if not task_id :
141- raise RuntimeError ( "`task_id` not found in response." )
150+ return None
142151 task = self ._ctx .client .tasks .get (task_id )
143152 return task
144153
@@ -192,7 +201,11 @@ def find(self) -> List[SystemRuntimeCache]:
192201 return [SystemRuntimeCache (self ._ctx , self ._path , ** cache ) for cache in caches ]
193202
194203 @overload
195- def destroy (self , cache : SystemRuntimeCache , / ) -> Task : ...
204+ def destroy (
205+ self , cache : SystemRuntimeCache , / , * , dry_run : Literal [False ] = False
206+ ) -> Task : ...
207+ @overload
208+ def destroy (self , cache : SystemRuntimeCache , / , * , dry_run : Literal [True ]) -> None : ...
196209 @overload
197210 def destroy (
198211 self ,
@@ -201,15 +214,25 @@ def destroy(
201214 language : str ,
202215 version : str ,
203216 image_name : str ,
204- dry_run : bool = False ,
217+ dry_run : Literal [ False ] = False ,
205218 ) -> Task : ...
219+ @overload
220+ def destroy (
221+ self ,
222+ / ,
223+ * ,
224+ language : str ,
225+ version : str ,
226+ image_name : str ,
227+ dry_run : Literal [True ] = True ,
228+ ) -> None : ...
206229
207230 def destroy (
208231 self ,
209232 cache : Optional [SystemRuntimeCache ] = None ,
210233 / ,
211234 ** kwargs ,
212- ) -> Task :
235+ ) -> Task | None :
213236 """
214237 Delete a content runtime package cache.
215238
@@ -231,6 +254,11 @@ def destroy(
231254 dry_run : bool, optional
232255 If `True`, the cache will not be destroyed, only the operation will be simulated.
233256
257+ Returns
258+ -------
259+ Task | None
260+ The task object if the operation was successful. If `dry_run=True`, `None` is returned.
261+
234262 Examples
235263 --------
236264 ```python
@@ -242,14 +270,14 @@ def destroy(
242270 first_runtime_cache = runtime_caches[0]
243271
244272 # Remove the cache
245- task = client.system.caches.runtime.destroy(first_runtime_cache, dry_run=True )
273+ task = client.system.caches.runtime.destroy(first_runtime_cache, dry_run=False )
246274
247275 # Or, remove the cache by specifying the cache's attributes
248276 task = client.system.caches.runtime.destroy(
249277 language="Python",
250278 version="3.12.5",
251279 image_name="Local",
252- dry_run=True ,
280+ dry_run=False ,
253281 )
254282 ```
255283 """
0 commit comments