| 74 | return self.options.max_retries |
| 75 | |
| 76 | def copy( |
| 77 | self, |
| 78 | *, |
| 79 | method: str | NotGiven = not_given, |
| 80 | url: str | NotGiven = not_given, |
| 81 | headers: Headers | NotGiven = not_given, |
| 82 | params: Query | NotGiven = not_given, |
| 83 | body: Body | NotGiven = not_given, |
| 84 | timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 85 | ) -> APIRequest: |
| 86 | # Note: we intentionally avoid `model_copy(deep=True)` here as fields like |
| 87 | # `files` and `content` can hold open file/IO objects which cannot be deep-copied. |
| 88 | # |
| 89 | # Instead we shallow-copy the options and then deep-copy only the JSON-safe mutable |
| 90 | # fields so that mutating the returned request never affects the original request. |
| 91 | options = model_copy(self.options) |
| 92 | options.json_data = _copy.deepcopy(options.json_data) |
| 93 | options.extra_json = _copy.deepcopy(options.extra_json) |
| 94 | options.params = _copy.deepcopy(options.params) |
| 95 | if is_given(options.headers): |
| 96 | options.headers = dict(options.headers) |
| 97 | |
| 98 | if is_given(method): |
| 99 | options.method = method |
| 100 | if is_given(url): |
| 101 | options.url = url |
| 102 | if is_given(headers): |
| 103 | options.headers = dict({name.lower(): (name, value) for name, value in headers.items()}.values()) |
| 104 | if is_given(params): |
| 105 | options.params = params |
| 106 | if not isinstance(body, NotGiven): |
| 107 | options.json_data = body |
| 108 | if not isinstance(timeout, NotGiven): |
| 109 | options.timeout = timeout |
| 110 | |
| 111 | return APIRequest( |
| 112 | options=options, |
| 113 | cast_to=self.cast_to, |
| 114 | stream=self.stream, |
| 115 | stream_cls=self.stream_cls, |
| 116 | retries_taken=self.retries_taken, |
| 117 | ) |
| 118 | |
| 119 | @override |
| 120 | def __repr__(self) -> str: |