Skip to content

Commit 09f8aa9

Browse files
authored
PYTHON-3072 Use _Address in more places (#871)
1 parent 9482019 commit 09f8aa9

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

pymongo/command_cursor.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from pymongo.errors import ConnectionFailure, InvalidOperation, OperationFailure
2323
from pymongo.message import _CursorAddress, _GetMore, _RawBatchGetMore
2424
from pymongo.response import PinnedResponse
25-
from pymongo.typings import _DocumentType
25+
from pymongo.typings import _Address, _DocumentType
2626

2727
if TYPE_CHECKING:
2828
from pymongo.client_session import ClientSession
@@ -38,7 +38,7 @@ def __init__(
3838
self,
3939
collection: "Collection[_DocumentType]",
4040
cursor_info: Mapping[str, Any],
41-
address: Optional[Tuple[str, Optional[int]]],
41+
address: Optional[_Address],
4242
batch_size: int = 0,
4343
max_await_time_ms: Optional[int] = None,
4444
session: Optional["ClientSession"] = None,
@@ -254,7 +254,7 @@ def cursor_id(self) -> int:
254254
return self.__id
255255

256256
@property
257-
def address(self) -> Optional[Tuple[str, Optional[int]]]:
257+
def address(self) -> Optional[_Address]:
258258
"""The (host, port) of the server used, or None.
259259
260260
.. versionadded:: 3.0
@@ -309,7 +309,7 @@ def __init__(
309309
self,
310310
collection: "Collection[_DocumentType]",
311311
cursor_info: Mapping[str, Any],
312-
address: Optional[Tuple[str, Optional[int]]],
312+
address: Optional[_Address],
313313
batch_size: int = 0,
314314
max_await_time_ms: Optional[int] = None,
315315
session: Optional["ClientSession"] = None,

pymongo/mongo_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
from pymongo.settings import TopologySettings
8787
from pymongo.topology import Topology, _ErrorContext
8888
from pymongo.topology_description import TOPOLOGY_TYPE, TopologyDescription
89-
from pymongo.typings import _CollationIn, _DocumentType, _Pipeline
89+
from pymongo.typings import _Address, _CollationIn, _DocumentType, _Pipeline
9090
from pymongo.uri_parser import (
9191
_check_options,
9292
_handle_option_deprecations,
@@ -1061,7 +1061,7 @@ def is_mongos(self) -> bool:
10611061
return self._server_property("server_type") == SERVER_TYPE.Mongos
10621062

10631063
@property
1064-
def nodes(self) -> FrozenSet[Tuple[str, Optional[int]]]:
1064+
def nodes(self) -> FrozenSet[_Address]:
10651065
"""Set of all currently connected servers.
10661066
10671067
.. warning:: When connected to a replica set the value of :attr:`nodes`

pymongo/uri_parser.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
)
4141
from pymongo.errors import ConfigurationError, InvalidURI
4242
from pymongo.srv_resolver import _HAVE_DNSPYTHON, _SrvResolver
43+
from pymongo.typings import _Address
4344

4445
SCHEME = "mongodb://"
4546
SCHEME_LEN = len(SCHEME)
@@ -114,9 +115,7 @@ def parse_ipv6_literal_host(
114115
return entity[1:i], entity[i + 2 :]
115116

116117

117-
def parse_host(
118-
entity: str, default_port: Optional[int] = DEFAULT_PORT
119-
) -> Tuple[str, Optional[int]]:
118+
def parse_host(entity: str, default_port: Optional[int] = DEFAULT_PORT) -> _Address:
120119
"""Validates a host string
121120
122121
Returns a 2-tuple of host followed by port where port is default_port
@@ -363,9 +362,7 @@ def split_options(
363362
return options
364363

365364

366-
def split_hosts(
367-
hosts: str, default_port: Optional[int] = DEFAULT_PORT
368-
) -> List[Tuple[str, Optional[int]]]:
365+
def split_hosts(hosts: str, default_port: Optional[int] = DEFAULT_PORT) -> List[_Address]:
369366
"""Takes a string of the form host1[:port],host2[:port]... and
370367
splits it into (host, port) tuples. If [:port] isn't present the
371368
default_port is used.

0 commit comments

Comments
 (0)