Skip to content

Commit e6e8266

Browse files
committed
[chore] remove useless cast and rename read socket exception
1 parent bb07ff9 commit e6e8266

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

pynats/client.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,14 @@
33
import re
44
import socket
55
from dataclasses import dataclass
6-
from typing import (
7-
BinaryIO,
8-
Callable,
9-
Dict,
10-
Match,
11-
Optional,
12-
Pattern,
13-
Tuple,
14-
Union,
15-
cast,
16-
)
6+
from typing import BinaryIO, Callable, Dict, Match, Optional, Pattern, Tuple, Union
177
from urllib.parse import urlparse
188

199
import pkg_resources
2010

2111
from pynats.exceptions import (
2212
NATSInvalidResponse,
23-
NATSSocketError,
13+
NATSReadSocketError,
2414
NATSUnexpectedResponse,
2515
)
2616
from pynats.nuid import NUID
@@ -284,11 +274,10 @@ def _readline(self, *, size: int = None) -> bytes:
284274
read = io.BytesIO()
285275

286276
while True:
287-
raw_bytes = self._socket_file.readline()
288-
if not raw_bytes:
289-
raise NATSSocketError(b"unable to read from socket")
277+
line = self._socket_file.readline()
278+
if not line:
279+
raise NATSReadSocketError()
290280

291-
line = cast(bytes, raw_bytes)
292281
read.write(line)
293282

294283
if size is not None:

pynats/exceptions.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
__all__ = ("NATSError", "NATSUnexpectedResponse", "NATSInvalidResponse")
1+
__all__ = (
2+
"NATSError",
3+
"NATSUnexpectedResponse",
4+
"NATSInvalidResponse",
5+
"NATSReadSocketError",
6+
)
27

38

49
class NATSError(Exception):
@@ -17,7 +22,6 @@ def __init__(self, line: bytes, *args, **kwargs) -> None:
1722
super().__init__()
1823

1924

20-
class NATSSocketError(NATSError):
21-
def __init__(self, line: bytes, *args, **kwargs) -> None:
22-
self.line = line
25+
class NATSReadSocketError(NATSError):
26+
def __init__(self) -> None:
2327
super().__init__()

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88

99
from pynats import NATSClient
10-
from pynats.exceptions import NATSSocketError
10+
from pynats.exceptions import NATSReadSocketError
1111

1212

1313
@pytest.fixture
@@ -188,7 +188,7 @@ def worker(client, connected_event):
188188
connected_event.set()
189189
try:
190190
client.wait()
191-
except NATSSocketError:
191+
except NATSReadSocketError:
192192
assert True
193193
except Exception:
194194
raise AssertionError("unexpected Exception raised")

0 commit comments

Comments
 (0)