44import json
55import shlex
66import textwrap
7+ import warnings
78from datetime import datetime , timedelta
89from pathlib import Path
910from typing import (
@@ -1173,18 +1174,27 @@ def logs(
11731174 def list (
11741175 self ,
11751176 all : bool = False ,
1176- filters : Iterable [ContainerListFilter ] = (),
1177+ filters : Union [ Iterable [ContainerListFilter ], Mapping [ str , Any ] ] = (),
11771178 ) -> List [Container ]:
11781179 """List the containers on the host.
11791180
11801181 Alias: `docker.ps(...)`
11811182
11821183 Parameters:
11831184 all: If `True`, also returns containers that are not running.
1185+ filters: Filters to apply when listing containers.
11841186
11851187 # Returns
11861188 A `List[python_on_whales.Container]`
11871189 """
1190+ if isinstance (filters , Mapping ):
1191+ filters = filters .items ()
1192+ warnings .warn (
1193+ "Passing filters as a mapping is deprecated, replace with an "
1194+ "iterable of tuples instead, as so:\n "
1195+ f"filters={ list (filters )} " ,
1196+ DeprecationWarning ,
1197+ )
11881198 full_cmd = self .docker_cmd
11891199 full_cmd += ["container" , "list" , "-q" , "--no-trunc" ]
11901200 full_cmd .add_flag ("--all" , all )
@@ -1222,20 +1232,20 @@ def pause(
12221232 @overload
12231233 def prune (
12241234 self ,
1225- filters : Iterable [ContainerListFilter ] = (),
1235+ filters : Union [ Iterable [ContainerListFilter ], Mapping [ str , Any ] ] = (),
12261236 stream_logs : Literal [True ] = ...,
12271237 ) -> Iterable [Tuple [str , bytes ]]: ...
12281238
12291239 @overload
12301240 def prune (
12311241 self ,
1232- filters : Iterable [ContainerListFilter ] = (),
1242+ filters : Union [ Iterable [ContainerListFilter ], Mapping [ str , Any ] ] = (),
12331243 stream_logs : Literal [False ] = ...,
12341244 ) -> None : ...
12351245
12361246 def prune (
12371247 self ,
1238- filters : Iterable [ContainerListFilter ] = (),
1248+ filters : Union [ Iterable [ContainerListFilter ], Mapping [ str , Any ] ] = (),
12391249 stream_logs : bool = False ,
12401250 ):
12411251 """Remove containers that are not running.
@@ -1247,11 +1257,13 @@ def prune(
12471257 the function returns `None`, but when it returns, then the prune operation has already been
12481258 done.
12491259 """
1250- if isinstance (filter , list ):
1251- raise TypeError (
1252- "since python-on-whales 0.38.0, the filter argument is expected to be "
1253- "a dict, not a list, please replace your function call by "
1254- "docker.container.prune(filters={...})"
1260+ if isinstance (filters , Mapping ):
1261+ filters = filters .items ()
1262+ warnings .warn (
1263+ "Passing filters as a mapping is deprecated, replace with an "
1264+ "iterable of tuples instead, as so:\n "
1265+ f"filters={ list (filters )} " ,
1266+ DeprecationWarning ,
12551267 )
12561268 full_cmd = self .docker_cmd + ["container" , "prune" , "--force" ]
12571269 full_cmd .add_args_iterable ("--filter" , (f"{ f [0 ]} ={ f [1 ]} " for f in filters ))
0 commit comments