Skip to content

Commit 3237d70

Browse files
committed
Fix raise from ... as suggested
1 parent 7e320b1 commit 3237d70

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

plugwise/helper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ async def _request_validate(self, resp: ClientResponse, method: str) -> etree:
164164
try:
165165
# Encode to ensure utf8 parsing
166166
xml = etree.XML(escape_illegal_xml_characters(result).encode())
167-
except etree.ParseError:
167+
except etree.ParseError as exc:
168168
LOGGER.warning("Smile returns invalid XML for %s", self._endpoint)
169-
raise InvalidXMLError
169+
raise InvalidXMLError from exc
170170

171171
return xml
172172

@@ -202,15 +202,15 @@ async def _request(
202202
)
203203
except (
204204
ClientError
205-
) as err: # ClientError is an ancestor class of ServerTimeoutError
205+
) as exc: # ClientError is an ancestor class of ServerTimeoutError
206206
if retry < 1:
207207
LOGGER.warning(
208208
"Failed sending %s %s to Plugwise Smile, error: %s",
209209
method,
210210
command,
211-
err,
211+
exc,
212212
)
213-
raise ConnectionFailedError
213+
raise ConnectionFailedError from exc
214214
return await self._request(command, retry - 1)
215215

216216
return await self._request_validate(resp, method)

tests/test_init.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ async def smile_status(self, request):
183183
with open(userdata, encoding="utf-8") as filedata:
184184
data = filedata.read()
185185
return aiohttp.web.Response(text=data)
186-
except OSError:
187-
raise aiohttp.web.HTTPNotFound
186+
except OSError as exc:
187+
raise aiohttp.web.HTTPNotFound from exc
188188

189189
@classmethod
190190
async def smile_http_accept(cls, request):
@@ -317,9 +317,9 @@ async def connect_wrapper(
317317
await self.connect(fail_auth=fail_auth)
318318
_LOGGER.error(" - invalid credentials not handled") # pragma: no cover
319319
raise self.ConnectError # pragma: no cover
320-
except pw_exceptions.InvalidAuthentication:
320+
except pw_exceptions.InvalidAuthentication as exc:
321321
_LOGGER.info(" + successfully aborted on credentials missing.")
322-
raise pw_exceptions.InvalidAuthentication
322+
raise pw_exceptions.InvalidAuthentication from exc
323323

324324
if raise_timeout:
325325
_LOGGER.warning("Connecting to device exceeding timeout in handling:")

0 commit comments

Comments
 (0)