Skip to content

Commit 1e4c23c

Browse files
committed
fix: rename TimeoutError to NutrientTimeoutError to avoid built-in conflict
- Python 3.3+ has a built-in TimeoutError that could conflict with our custom exception - Renamed to NutrientTimeoutError to ensure no import conflicts in CI - Removed type: ignore comments by properly typing test variables - Fixed all linting and formatting issues
1 parent 1e114ea commit 1e4c23c

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

src/nutrient_dws/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
AuthenticationError,
1010
FileProcessingError,
1111
NutrientError,
12-
TimeoutError,
12+
NutrientTimeoutError,
1313
ValidationError,
1414
)
1515

@@ -20,6 +20,6 @@
2020
"FileProcessingError",
2121
"NutrientClient",
2222
"NutrientError",
23-
"TimeoutError",
23+
"NutrientTimeoutError",
2424
"ValidationError",
2525
]

src/nutrient_dws/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self, message: str, errors: Optional[Dict[str, Any]] = None) -> Non
7171
self.errors = errors or {}
7272

7373

74-
class TimeoutError(NutrientError):
74+
class NutrientTimeoutError(NutrientError):
7575
"""Raised when a request times out."""
7676

7777
pass

src/nutrient_dws/http_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from requests.adapters import HTTPAdapter
99
from urllib3.util.retry import Retry
1010

11-
from nutrient_dws.exceptions import APIError, AuthenticationError, TimeoutError, ValidationError
11+
from nutrient_dws.exceptions import (
12+
APIError,
13+
AuthenticationError,
14+
NutrientTimeoutError,
15+
ValidationError,
16+
)
1217

1318
logger = logging.getLogger(__name__)
1419

@@ -154,7 +159,7 @@ def post(
154159
timeout=self._timeout,
155160
)
156161
except requests.exceptions.Timeout as e:
157-
raise TimeoutError(f"Request timed out after {self._timeout} seconds") from e
162+
raise NutrientTimeoutError(f"Request timed out after {self._timeout} seconds") from e
158163
except requests.exceptions.ConnectionError as e:
159164
raise APIError(f"Connection error: {e!s}") from e
160165
except requests.exceptions.RequestException as e:

tests/unit/test_exceptions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
AuthenticationError,
66
FileProcessingError,
77
NutrientError,
8-
TimeoutError,
8+
NutrientTimeoutError,
99
ValidationError,
1010
)
1111

@@ -110,16 +110,16 @@ def test_error_with_details(self):
110110
assert exc.errors == errors
111111

112112

113-
class TestTimeoutError:
113+
class TestNutrientTimeoutError:
114114
"""Test timeout error."""
115115

116116
def test_inheritance(self):
117-
"""Test that TimeoutError inherits from NutrientError."""
118-
assert issubclass(TimeoutError, NutrientError)
117+
"""Test that NutrientTimeoutError inherits from NutrientError."""
118+
assert issubclass(NutrientTimeoutError, NutrientError)
119119

120120
def test_instantiation(self):
121121
"""Test basic instantiation."""
122-
exc = TimeoutError("Request timed out")
122+
exc = NutrientTimeoutError("Request timed out")
123123
assert str(exc) == "Request timed out"
124124

125125

tests/unit/test_file_handler.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Unit tests for file handling utilities."""
22

33
import io
4+
from typing import Any
45

56
import pytest
67

@@ -76,8 +77,9 @@ def test_file_like_object_with_name(self, tmp_path):
7677

7778
def test_unsupported_input_type(self):
7879
"""Test handling of unsupported input type."""
80+
invalid_input: Any = 123
7981
with pytest.raises(ValueError, match="Unsupported file input type"):
80-
prepare_file_input(123) # type: ignore
82+
prepare_file_input(invalid_input)
8183

8284

8385
class TestPrepareFileForUpload:
@@ -227,6 +229,7 @@ class NonSeekable:
227229
def read(self):
228230
return b"content"
229231

230-
size = get_file_size(NonSeekable()) # type: ignore
232+
non_seekable: Any = NonSeekable()
233+
size = get_file_size(non_seekable)
231234

232235
assert size is None

tests/unit/test_http_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
import requests
77
import responses
88

9-
from nutrient_dws.exceptions import APIError, AuthenticationError, TimeoutError, ValidationError
9+
from nutrient_dws.exceptions import (
10+
APIError,
11+
AuthenticationError,
12+
NutrientTimeoutError,
13+
ValidationError,
14+
)
1015
from nutrient_dws.http_client import HTTPClient
1116

1217

@@ -158,7 +163,7 @@ def test_post_timeout(self):
158163
with patch.object(client._session, "post") as mock_post:
159164
mock_post.side_effect = requests.exceptions.Timeout()
160165

161-
with pytest.raises(TimeoutError, match="Request timed out"):
166+
with pytest.raises(NutrientTimeoutError, match="Request timed out"):
162167
client.post("/test")
163168

164169
def test_post_connection_error(self):

0 commit comments

Comments
 (0)