@@ -180,25 +180,25 @@ def bridge_ip(self, container_id: str) -> str:
180180 """
181181 container = self .get_container (container_id )
182182 network_name = self .network_name (container_id )
183- return cast ( str , container ["NetworkSettings" ]["Networks" ][network_name ]["IPAddress" ])
183+ return str ( container ["NetworkSettings" ]["Networks" ][network_name ]["IPAddress" ])
184184
185185 def network_name (self , container_id : str ) -> str :
186186 """
187187 Get the name of the network this container runs on
188188 """
189189 container = self .get_container (container_id )
190- name = container ["HostConfig" ]["NetworkMode" ]
190+ name = str ( container ["HostConfig" ]["NetworkMode" ])
191191 if name == "default" :
192192 return "bridge"
193- return cast ( str , name )
193+ return name
194194
195195 def gateway_ip (self , container_id : str ) -> str :
196196 """
197197 Get the gateway ip address for a container.
198198 """
199199 container = self .get_container (container_id )
200200 network_name = self .network_name (container_id )
201- return cast ( str , container ["NetworkSettings" ]["Networks" ][network_name ]["Gateway" ])
201+ return str ( container ["NetworkSettings" ]["Networks" ][network_name ]["Gateway" ])
202202
203203 def get_connection_mode (self ) -> ConnectionMode :
204204 """
@@ -235,7 +235,8 @@ def host(self) -> str:
235235 return "localhost"
236236 if "http" in url .scheme or "tcp" in url .scheme and url .hostname :
237237 # see https://github.com/testcontainers/testcontainers-python/issues/415
238- if url .hostname == "localnpipe" and utils .is_windows ():
238+ hostname = url .hostname
239+ if not hostname or (hostname == "localnpipe" and utils .is_windows ()):
239240 return "localhost"
240241 return cast (str , url .hostname )
241242 if utils .inside_container () and ("unix" in url .scheme or "npipe" in url .scheme ):
0 commit comments