Repository navigation
Let unwrap() accept the ApiError of another generated client - #2
Merged
Merged
Conversation
error_type and ApiErrorLike are new API: a minor version, not a patch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
shellrent-internal-sdkwill reuse authentication, HTTP client and error handling from this package, but its generated client has its ownApiError: withunwrap()its documented errors becameUnexpectedStatusinstead ofApiException.unwrap(response, *, error_type=None): another generated client passes its ownApiError. Witherror_type=None(or this package'sApiError) the signature and the inferred types are unchanged. With anothererror_type,responseis typed structurally, since the other client'sResponseis a different class.ApiErrorLike, aProtocolwith read-onlyerror: intandmessage: str | None, exported fromshellrent_sdk.ApiException.erroris typed with it, so it no longer depends on this package'sApiError.ApiExceptionreadsHTTP <status>when the envelope has nomessage.CLAUDE.md:unwrap()andApiExceptionadded to the interface used byshellrent-internal-sdk.CHANGELOG.md: section[0.2.0](new API, so a minor release).Notes for reviewers
e.error.messageis nowstr | Noneinstead ofstr, anddata/metaneedisinstance(e.error, ApiError). Runtime behaviour is the same, but mypy-strict code that reads those fields must narrow first.unwrap(r, error_type=OtherApiError)does not type-check when the body is an envelope too, because it also haserrorandmessage, so mypy cannot tell the two apart. The other client should define its ownunwrap()that calls this one; the example is in the docstring and covered by the tests.unwrap()still raises this package'sUnexpectedStatus, not the other client's.Test plan
tests/unit/test_errors.py: another client'sApiErrorpassed witherror_typeraisesApiException; the body is returned with the right type (checked withassert_type);ApiExceptionwithoutmessage; this package'sApiErroris the default.ruff format,ruff check,mypy,pytest(119 passed)--resolution lowest-direct🤖 Generated with Claude Code