From 727dcaace44ece77a54336bd329dac5230c1c0ee Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 28 Feb 2026 13:30:31 -0500 Subject: [PATCH] Add type annotations to `ironicclient/exc.py` Changes: Add type annotations following code conventions. Added file to the migrated files list. Change-Id: Ib1a69cb63c2d6896009997b79197b0711593f187 Signed-off-by: Karan Anand --- ironicclient/exc.py | 30 ++++++++++++++++++++++-------- pyproject.toml | 1 + 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ironicclient/exc.py b/ironicclient/exc.py index aa81914c3..6e04f4d45 100644 --- a/ironicclient/exc.py +++ b/ironicclient/exc.py @@ -10,6 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import annotations + +import requests # type: ignore[import-untyped] + from ironicclient.common.apiclient import exceptions from ironicclient.common.apiclient.exceptions import * # noqa @@ -46,11 +50,15 @@ class StateTransitionTimeout(exceptions.ClientException): def from_response( # type: ignore[no-redef] - response, message=None, traceback=None, method=None, url=None -): + response: requests.Response, + message: str | None = None, + traceback: str | None = None, + method: str | None = None, + url: str | None = None, +) -> exceptions.HttpError: """Return an HttpError instance based on response from httplib/requests.""" - error_body = {} + error_body: dict[str, str] = {} if message: error_body['message'] = message if traceback: @@ -61,13 +69,19 @@ def from_response( # type: ignore[no-redef] # ability to get all necessary information in method `from_response` # from common code, which expecting response object from `requests` # library instead of object from `httplib/httplib2` library. - response.status_code = response.status - response.headers = { - 'Content-Type': response.getheader('content-type', "")} + response.status_code = response.status # type: ignore[attr-defined] + response.headers = { # type: ignore[assignment] + 'Content-Type': + response.getheader( # type: ignore[attr-defined] + 'content-type', "")} if hasattr(response, 'status_code'): # NOTE(jiangfei): These modifications allow SessionClient # to handle faultstring. - response.json = lambda: {'error': error_body} + response.json = ( # type: ignore[method-assign] + lambda: { # type: ignore[misc,assignment] + 'error': error_body}) - return exceptions.from_response(response, method=method, url=url) + return exceptions.from_response( + response, method=method or "", url=url or "" + ) diff --git a/pyproject.toml b/pyproject.toml index 31bef68b2..0998a37b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,4 +15,5 @@ files = [ "ironicclient/common/apiclient/exceptions.py", "ironicclient/common/apiclient/base.py", "ironicclient/common/base.py", + "ironicclient/exc.py", ] \ No newline at end of file