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