Skip to content

Commit 304c8e9

Browse files
chore(deps): lock file maintenance (#1150)
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
1 parent 6e76310 commit 304c8e9

3 files changed

Lines changed: 2104 additions & 2102 deletions

File tree

‎src/apify_client/errors.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ class ApifyApiError(ApifyClientError):
4141

4242
def __new__(cls, response: HttpResponse, attempt: int, *, method: str = 'GET') -> Self: # noqa: ARG004
4343
"""Dispatch to the subclass matching the response's HTTP status code, if any."""
44-
instance = super().__new__(cls)
4544
if cls is ApifyApiError:
4645
status = response.status_code
4746
mapped = _STATUS_TO_CLASS.get(status)
4847
if mapped is None and status >= HTTPStatus.INTERNAL_SERVER_ERROR:
4948
mapped = ServerError
50-
if mapped is not None:
51-
# Retagging is runtime-equivalent to allocating `mapped` directly, but keeps the return type `Self`.
52-
instance.__class__ = mapped
53-
return instance
49+
# Every mapped class subclasses `ApifyApiError`, so the `issubclass` check always holds; it narrows `mapped`
50+
# to `type[Self]` for the return type.
51+
if mapped is not None and issubclass(mapped, cls):
52+
return super().__new__(mapped)
53+
return super().__new__(cls)
5454

5555
def __init__(self, response: HttpResponse, attempt: int, *, method: str = 'GET') -> None:
5656
"""Initialize the API error from a failed response.

0 commit comments

Comments
 (0)