Skip to content

Commit a2f7f88

Browse files
authored
Merge pull request #278 from squat/type_connect
nats: add typing to main connect function
2 parents 3420e1c + 9e86d20 commit a2f7f88

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

nats/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313
#
14+
from typing import List, Union
1415

1516
from .aio.client import Client as NATS
1617

1718

18-
async def connect(servers=["nats://localhost:4222"], **options) -> NATS:
19+
async def connect(
20+
servers: Union[str, List[str]] = ["nats://localhost:4222"],
21+
**options
22+
) -> NATS:
1923
"""
2024
:param servers: List of servers to connect.
2125
:param options: NATS connect options.

nats/aio/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def __init__(self) -> None:
219219

220220
async def connect(
221221
self,
222-
servers: List[str] = ["nats://127.0.0.1:4222"],
222+
servers: Union[str, List[str]] = ["nats://localhost:4222"],
223223
error_cb: Optional[ErrorCallback] = None,
224224
disconnected_cb: Optional[Callback] = None,
225225
closed_cb: Optional[Callback] = None,
@@ -1083,11 +1083,11 @@ def _setup_server_pool(self, connect_url: Union[str, List[str]]) -> None:
10831083
try:
10841084
if "nats://" in connect_url or "tls://" in connect_url:
10851085
# Closer to how the Go client handles this.
1086-
# e.g. nats://127.0.0.1:4222
1086+
# e.g. nats://localhost:4222
10871087
uri = urlparse(connect_url)
10881088
elif ":" in connect_url:
10891089
# Expand the scheme for the user
1090-
# e.g. 127.0.0.1:4222
1090+
# e.g. localhost:4222
10911091
uri = urlparse(f"nats://{connect_url}")
10921092
else:
10931093
# Just use the endpoint with the default NATS port.

0 commit comments

Comments
 (0)