Skip to content

Commit dc290f4

Browse files
authored
[docker] Fix some incomplete types (#14817)
1 parent 0e10493 commit dc290f4

File tree

15 files changed

+170
-145
lines changed

15 files changed

+170
-145
lines changed

stubs/docker/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version = "7.1.*"
22
upstream_repository = "https://github.com/docker/docker-py"
3-
requires = ["types-requests", "urllib3>=2"]
3+
requires = ["types-paramiko", "types-requests", "urllib3>=2"]

stubs/docker/docker/api/image.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from _typeshed import Incomplete
1+
import logging
22
from typing import Any
33

4-
log: Incomplete
4+
log: logging.Logger
55

66
class ImageApiMixin:
77
def get_image(self, image: str, chunk_size: int | None = 2097152): ...

stubs/docker/docker/api/swarm.pyi

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
from _typeshed import Incomplete
1+
import logging
2+
from typing import Literal
23

3-
log: Incomplete
4+
from docker.types.swarm import SwarmSpec
5+
6+
log: logging.Logger
47

58
class SwarmApiMixin:
6-
def create_swarm_spec(self, *args, **kwargs): ...
9+
def create_swarm_spec(self, *args, **kwargs) -> SwarmSpec: ...
710
def get_unlock_key(self): ...
811
def init_swarm(
912
self,
@@ -20,17 +23,17 @@ class SwarmApiMixin:
2023
def inspect_node(self, node_id): ...
2124
def join_swarm(
2225
self, remote_addrs, join_token, listen_addr: str = "0.0.0.0:2377", advertise_addr=None, data_path_addr=None
23-
): ...
24-
def leave_swarm(self, force: bool = False): ...
26+
) -> Literal[True]: ...
27+
def leave_swarm(self, force: bool = False) -> Literal[True]: ...
2528
def nodes(self, filters=None): ...
26-
def remove_node(self, node_id, force: bool = False): ...
27-
def unlock_swarm(self, key): ...
28-
def update_node(self, node_id, version, node_spec=None): ...
29+
def remove_node(self, node_id, force: bool = False) -> Literal[True]: ...
30+
def unlock_swarm(self, key) -> Literal[True]: ...
31+
def update_node(self, node_id, version, node_spec=None) -> Literal[True]: ...
2932
def update_swarm(
3033
self,
3134
version,
3235
swarm_spec=None,
3336
rotate_worker_token: bool = False,
3437
rotate_manager_token: bool = False,
3538
rotate_manager_unlock_key: bool = False,
36-
): ...
39+
) -> Literal[True]: ...

stubs/docker/docker/credentials/store.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from _typeshed import Incomplete
22

33
class Store:
4-
program: Incomplete
5-
exe: Incomplete
4+
program: str
5+
exe: str | None
66
environment: Incomplete
7-
def __init__(self, program, environment=None) -> None: ...
7+
def __init__(self, program: str, environment=None) -> None: ...
88
def get(self, server): ...
99
def store(self, server, username, secret): ...
1010
def erase(self, server) -> None: ...

stubs/docker/docker/errors.pyi

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from _typeshed import Incomplete
21
from collections.abc import Iterator, Mapping
3-
from typing import NoReturn
2+
from typing import Any, NoReturn
43

54
from docker.models.containers import Container
5+
from docker.models.images import Image
66
from requests import HTTPError, Response
77

88
class DockerException(Exception): ...
@@ -35,11 +35,13 @@ class NullResource(DockerException, ValueError): ...
3535

3636
class ContainerError(DockerException):
3737
container: Container
38-
exit_status: Incomplete
39-
command: Incomplete
40-
image: Incomplete
38+
exit_status: int
39+
command: str | list[str] | None
40+
image: str | Image
4141
stderr: str | None
42-
def __init__(self, container: Container, exit_status, command, image, stderr: str | None) -> None: ...
42+
def __init__(
43+
self, container: Container, exit_status: int, command: str | list[str] | None, image: str | Image, stderr: str | None
44+
) -> None: ...
4345

4446
class StreamParseError(RuntimeError):
4547
msg: str
@@ -52,7 +54,7 @@ class BuildError(DockerException):
5254

5355
class ImageLoadError(DockerException): ...
5456

55-
def create_unexpected_kwargs_error(name, kwargs: Mapping[str, Incomplete]) -> NoReturn: ...
57+
def create_unexpected_kwargs_error(name, kwargs: Mapping[str, Any]) -> NoReturn: ...
5658

5759
class MissingContextParameter(DockerException):
5860
param: str

stubs/docker/docker/models/services.pyi

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from _typeshed import Incomplete
2-
31
from .resource import Collection, Model
42

53
class Service(Model):
@@ -21,7 +19,7 @@ class ServiceCollection(Collection[Service]):
2119
def get(self, service_id, insert_defaults=None): ...
2220
def list(self, **kwargs): ...
2321

24-
CONTAINER_SPEC_KWARGS: Incomplete
25-
TASK_TEMPLATE_KWARGS: Incomplete
26-
CREATE_SERVICE_KWARGS: Incomplete
27-
PLACEMENT_KWARGS: Incomplete
22+
CONTAINER_SPEC_KWARGS: list[str]
23+
TASK_TEMPLATE_KWARGS: list[str]
24+
CREATE_SERVICE_KWARGS: list[str]
25+
PLACEMENT_KWARGS: list[str]
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
from _typeshed import Incomplete
2-
31
import urllib3
42
import urllib3.connection
53
from docker.transport.basehttpadapter import BaseHTTPAdapter
4+
from docker.transport.npipesocket import NpipeSocket
5+
from urllib3._collections import RecentlyUsedContainer as urllib3_RecentlyUsedContainer
66

7-
RecentlyUsedContainer: Incomplete
7+
RecentlyUsedContainer = urllib3_RecentlyUsedContainer
88

99
class NpipeHTTPConnection(urllib3.connection.HTTPConnection):
10-
npipe_path: Incomplete
11-
timeout: Incomplete
12-
def __init__(self, npipe_path, timeout: int = 60) -> None: ...
13-
sock: Incomplete
10+
npipe_path: str
11+
timeout: int
12+
def __init__(self, npipe_path: str, timeout: int = 60) -> None: ...
13+
sock: NpipeSocket | None
1414
def connect(self) -> None: ...
1515

1616
class NpipeHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
17-
npipe_path: Incomplete
18-
timeout: Incomplete
19-
def __init__(self, npipe_path, timeout: int = 60, maxsize: int = 10) -> None: ...
17+
npipe_path: str
18+
timeout: urllib3.Timeout
19+
def __init__(self, npipe_path: str, timeout: int = 60, maxsize: int = 10) -> None: ...
2020

2121
class NpipeHTTPAdapter(BaseHTTPAdapter):
22-
__attrs__: Incomplete
23-
npipe_path: Incomplete
24-
timeout: Incomplete
25-
max_pool_size: Incomplete
26-
pools: Incomplete
27-
def __init__(self, base_url, timeout: int = 60, pool_connections=..., max_pool_size=...) -> None: ...
22+
__attrs__: list[str]
23+
npipe_path: str
24+
timeout: int
25+
max_pool_size: int
26+
pools: RecentlyUsedContainer
27+
def __init__(self, base_url: str, timeout: int = 60, pool_connections: int = 25, max_pool_size: int = 10) -> None: ...
2828
def get_connection(self, url, proxies=None): ...
2929
def request_url(self, request, proxies): ...
Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import io
2-
from _typeshed import Incomplete
2+
from _typeshed import ReadableBuffer
3+
from typing import Any, Literal, NoReturn
4+
from typing_extensions import TypeAlias
35

46
cERROR_PIPE_BUSY: int
57
cSECURITY_SQOS_PRESENT: int
@@ -8,42 +10,48 @@ MAXIMUM_RETRY_COUNT: int
810

911
def check_closed(f): ...
1012

13+
_PyHANDLE: TypeAlias = Any # pywin32._win32typing.PyHANDLE
14+
1115
class NpipeSocket:
12-
def __init__(self, handle=None) -> None: ...
16+
def __init__(self, handle: _PyHANDLE | None = None) -> None: ...
1317
def accept(self) -> None: ...
1418
def bind(self, address) -> None: ...
1519
def close(self) -> None: ...
16-
flags: Incomplete
17-
def connect(self, address, retry_count: int = 0): ...
18-
def connect_ex(self, address): ...
19-
def detach(self): ...
20-
def dup(self): ...
21-
def getpeername(self): ...
22-
def getsockname(self): ...
23-
def getsockopt(self, level, optname, buflen=None) -> None: ...
24-
def ioctl(self, control, option) -> None: ...
25-
def listen(self, backlog) -> None: ...
26-
def makefile(self, mode=None, bufsize=None): ...
27-
def recv(self, bufsize, flags: int = 0): ...
28-
def recvfrom(self, bufsize, flags: int = 0): ...
29-
def recvfrom_into(self, buf, nbytes: int = 0, flags: int = 0): ...
30-
def recv_into(self, buf, nbytes: int = 0): ...
31-
def send(self, string, flags: int = 0): ...
32-
def sendall(self, string, flags: int = 0): ...
33-
def sendto(self, string, address): ...
34-
def setblocking(self, flag): ...
35-
def settimeout(self, value) -> None: ...
36-
def gettimeout(self): ...
37-
def setsockopt(self, level, optname, value) -> None: ...
38-
def shutdown(self, how): ...
20+
flags: int
21+
def connect(self, address: str, retry_count: int = 0) -> None: ...
22+
def connect_ex(self, address: str) -> None: ...
23+
def detach(self) -> _PyHANDLE | None: ...
24+
def dup(self) -> NpipeSocket: ...
25+
def getpeername(self) -> str: ...
26+
def getsockname(self) -> str: ...
27+
# NotImplementedError
28+
def getsockopt(self, level, optname, buflen=None) -> NoReturn: ...
29+
# NotImplementedError
30+
def ioctl(self, control, option) -> NoReturn: ...
31+
# NotImplementedError
32+
def listen(self, backlog) -> NoReturn: ...
33+
def makefile(self, mode: str | None = None, bufsize: int | None = None) -> io.BufferedReader: ...
34+
def recv(self, bufsize: int, flags: int = 0) -> str: ...
35+
def recvfrom(self, bufsize: int, flags: int = 0) -> tuple[str, str]: ...
36+
def recvfrom_into(self, buf: memoryview | ReadableBuffer, nbytes: int = 0, flags: int = 0) -> tuple[int, str]: ...
37+
def recv_into(self, buf: memoryview | ReadableBuffer, nbytes: int = 0) -> int: ...
38+
def send(self, string: str, flags: int = 0) -> int: ...
39+
def sendall(self, string: str, flags: int = 0) -> int: ...
40+
def sendto(self, string: str, address: str) -> int: ...
41+
def setblocking(self, flag: bool) -> None: ...
42+
def settimeout(self, value: float | None) -> None: ...
43+
def gettimeout(self) -> int | None: ...
44+
# NotImplementedError
45+
def setsockopt(self, level, optname, value) -> NoReturn: ...
46+
def shutdown(self, how) -> None: ...
3947

4048
class NpipeFileIOBase(io.RawIOBase):
41-
sock: Incomplete
42-
def __init__(self, npipe_socket) -> None: ...
49+
sock: NpipeSocket
50+
def __init__(self, npipe_socket: NpipeSocket) -> None: ...
4351
def close(self) -> None: ...
4452
def fileno(self): ...
45-
def isatty(self): ...
46-
def readable(self): ...
47-
def readinto(self, buf): ...
48-
def seekable(self): ...
49-
def writable(self): ...
53+
def isatty(self) -> Literal[False]: ...
54+
def readable(self) -> Literal[True]: ...
55+
def readinto(self, buf: memoryview | ReadableBuffer) -> int: ...
56+
def seekable(self) -> Literal[False]: ...
57+
def writable(self) -> Literal[False]: ...
Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import socket
2-
from _typeshed import Incomplete
2+
import subprocess
33

44
import urllib3
55
import urllib3.connection
66
from docker.transport.basehttpadapter import BaseHTTPAdapter
7+
from paramiko import SSHClient, Transport
8+
from urllib3._collections import RecentlyUsedContainer as urllib3_RecentlyUsedContainer
79

8-
RecentlyUsedContainer: Incomplete
10+
RecentlyUsedContainer = urllib3_RecentlyUsedContainer
911

1012
class SSHSocket(socket.socket):
11-
host: Incomplete
12-
port: Incomplete
13-
user: Incomplete
14-
proc: Incomplete
15-
def __init__(self, host) -> None: ...
13+
host: str
14+
port: str | None
15+
user: str | None
16+
proc: subprocess.Popen[bytes] | None
17+
def __init__(self, host: str) -> None: ...
1618
def connect(self, **kwargs) -> None: ... # type:ignore[override]
1719
def sendall(self, data) -> None: ... # type:ignore[override]
1820
def send(self, data): ... # type:ignore[override]
@@ -21,27 +23,31 @@ class SSHSocket(socket.socket):
2123
def close(self) -> None: ...
2224

2325
class SSHConnection(urllib3.connection.HTTPConnection):
24-
ssh_transport: Incomplete
25-
timeout: Incomplete
26-
ssh_host: Incomplete
27-
def __init__(self, ssh_transport=None, timeout: int = 60, host=None) -> None: ...
28-
sock: Incomplete
26+
ssh_transport: Transport | None
27+
timeout: int
28+
ssh_host: str | None
29+
def __init__(self, ssh_transport: Transport | None = None, timeout: int = 60, host: str | None = None) -> None: ...
30+
sock: SSHSocket | None
2931
def connect(self) -> None: ...
3032

3133
class SSHConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
3234
scheme: str
33-
ssh_transport: Incomplete
34-
timeout: Incomplete
35-
ssh_host: Incomplete
36-
def __init__(self, ssh_client=None, timeout: int = 60, maxsize: int = 10, host=None) -> None: ...
35+
ssh_transport: Transport | None
36+
timeout: urllib3.Timeout
37+
ssh_host: str | None
38+
def __init__(
39+
self, ssh_client: SSHClient | None = None, timeout: int = 60, maxsize: int = 10, host: str | None = None
40+
) -> None: ...
3741

3842
class SSHHTTPAdapter(BaseHTTPAdapter):
39-
__attrs__: Incomplete
40-
ssh_client: Incomplete
41-
ssh_host: Incomplete
42-
timeout: Incomplete
43-
max_pool_size: Incomplete
44-
pools: Incomplete
45-
def __init__(self, base_url, timeout: int = 60, pool_connections=25, max_pool_size=10, shell_out: bool = False) -> None: ...
46-
def get_connection(self, url, proxies=None): ...
43+
__attrs__: list[str]
44+
ssh_client: SSHClient | None
45+
ssh_host: str
46+
timeout: int
47+
max_pool_size: int
48+
pools: int
49+
def __init__(
50+
self, base_url: str, timeout: int = 60, pool_connections: int = 25, max_pool_size: int = 10, shell_out: bool = False
51+
) -> None: ...
52+
def get_connection(self, url: str | bytes, proxies=None) -> SSHConnectionPool: ...
4753
def close(self) -> None: ...
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
from _typeshed import Incomplete
1+
import socket
22

33
import urllib3
44
import urllib3.connection
55
from docker.transport.basehttpadapter import BaseHTTPAdapter
6+
from requests import PreparedRequest
7+
from urllib3._collections import RecentlyUsedContainer as urllib3_RecentlyUsedContainer
68

7-
RecentlyUsedContainer: Incomplete
9+
RecentlyUsedContainer = urllib3_RecentlyUsedContainer
810

911
class UnixHTTPConnection(urllib3.connection.HTTPConnection):
10-
base_url: Incomplete
11-
unix_socket: Incomplete
12-
timeout: Incomplete
13-
def __init__(self, base_url, unix_socket, timeout: int = 60) -> None: ...
14-
sock: Incomplete
12+
base_url: str
13+
unix_socket: str
14+
timeout: int
15+
def __init__(self, base_url: str, unix_socket: str, timeout: int = 60) -> None: ...
16+
sock: socket.socket | None
1517
def connect(self) -> None: ...
1618

1719
class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
18-
base_url: Incomplete
19-
socket_path: Incomplete
20-
timeout: Incomplete
21-
def __init__(self, base_url, socket_path, timeout: int = 60, maxsize: int = 10) -> None: ...
20+
base_url: str
21+
socket_path: str
22+
timeout: urllib3.Timeout
23+
def __init__(self, base_url: str, socket_path: str, timeout: int = 60, maxsize: int = 10) -> None: ...
2224

2325
class UnixHTTPAdapter(BaseHTTPAdapter):
24-
__attrs__: Incomplete
25-
socket_path: Incomplete
26-
timeout: Incomplete
27-
max_pool_size: Incomplete
28-
pools: Incomplete
29-
def __init__(self, socket_url, timeout: int = 60, pool_connections=25, max_pool_size=10) -> None: ...
30-
def get_connection(self, url, proxies=None): ...
31-
def request_url(self, request, proxies): ...
26+
__attrs__: list[str]
27+
socket_path: str
28+
timeout: int
29+
max_pool_size: int
30+
pools: RecentlyUsedContainer
31+
def __init__(self, socket_url: str, timeout: int = 60, pool_connections: int = 25, max_pool_size: int = 10) -> None: ...
32+
def get_connection(self, url: bytes | str, proxies=None) -> UnixHTTPConnectionPool: ...
33+
# proxies is unused
34+
def request_url(self, request: PreparedRequest, proxies) -> str: ...

0 commit comments

Comments
 (0)