Skip to content

Commit 4ba71c8

Browse files
committed
Add type annotations to _ConnectionParameters and its constructing function
1 parent d27cbcd commit 4ba71c8

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

asyncpg/connect_utils.py

+31-19
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,17 @@ class SSLNegotiation(compat.StrEnum):
5252
direct = "direct"
5353

5454

55-
_ConnectionParameters = collections.namedtuple(
56-
'ConnectionParameters',
57-
[
58-
'user',
59-
'password',
60-
'database',
61-
'ssl',
62-
'sslmode',
63-
'ssl_negotiation',
64-
'server_settings',
65-
'target_session_attrs',
66-
'krbsrvname',
67-
'gsslib',
68-
])
55+
class _ConnectionParameters(typing.NamedTuple):
56+
user: str
57+
password: typing.Optional[str]
58+
database: str
59+
ssl: typing.Union[ssl_module.SSLContext, bool, str, SSLMode, None]
60+
sslmode: SSLMode
61+
ssl_negotiation: SSLNegotiation
62+
server_settings: typing.Optional[typing.Dict[str, str]]
63+
target_session_attrs: "SessionAttribute"
64+
krbsrvname: typing.Optional[str]
65+
gsslib: str
6966

7067

7168
_ClientConfiguration = collections.namedtuple(
@@ -276,10 +273,25 @@ def _dot_postgresql_path(filename) -> typing.Optional[pathlib.Path]:
276273
return (homedir / '.postgresql' / filename).resolve()
277274

278275

279-
def _parse_connect_dsn_and_args(*, dsn, host, port, user,
280-
password, passfile, database, ssl,
281-
direct_tls, server_settings,
282-
target_session_attrs, krbsrvname, gsslib):
276+
def _parse_connect_dsn_and_args(
277+
*,
278+
dsn: str,
279+
host: typing.Union[str, typing.List[str], typing.Tuple[str]],
280+
port: typing.Union[int, typing.List[int]],
281+
user: typing.Optional[str],
282+
password: typing.Optional[str],
283+
passfile: typing.Union[str, pathlib.Path, None],
284+
database: typing.Optional[str],
285+
ssl: typing.Union[bool, None, str, SSLMode],
286+
direct_tls: typing.Optional[bool],
287+
server_settings: typing.Optional[typing.Dict[str, str]],
288+
target_session_attrs: typing.Optional[str],
289+
krbsrvname: typing.Optional[str],
290+
gsslib: typing.Optional[str],
291+
) -> typing.Tuple[
292+
typing.List[typing.Union[str, typing.Tuple[str, int]]],
293+
_ConnectionParameters,
294+
]:
283295
# `auth_hosts` is the version of host information for the purposes
284296
# of reading the pgpass file.
285297
auth_hosts = None
@@ -502,7 +514,7 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
502514
database=database, user=user,
503515
passfile=passfile)
504516

505-
addrs = []
517+
addrs: typing.List[typing.Union[str, typing.Tuple[str, int]]] = []
506518
have_tcp_addrs = False
507519
for h, p in zip(host, port):
508520
if h.startswith('/'):

0 commit comments

Comments
 (0)