| 766 | |
| 767 | @final |
| 768 | class FinalRequestOptions(pydantic.BaseModel): |
| 769 | method: str |
| 770 | url: str |
| 771 | params: Query = {} |
| 772 | headers: Union[Headers, NotGiven] = NotGiven() |
| 773 | max_retries: Union[int, NotGiven] = NotGiven() |
| 774 | timeout: Union[float, Timeout, None, NotGiven] = NotGiven() |
| 775 | files: Union[HttpxRequestFiles, None] = None |
| 776 | idempotency_key: Union[str, None] = None |
| 777 | post_parser: Union[Callable[[Any], Any], NotGiven] = NotGiven() |
| 778 | follow_redirects: Union[bool, None] = None |
| 779 | |
| 780 | # It should be noted that we cannot use `json` here as that would override |
| 781 | # a BaseModel method in an incompatible fashion. |
| 782 | json_data: Union[Body, None] = None |
| 783 | extra_json: Union[AnyMapping, None] = None |
| 784 | |
| 785 | if PYDANTIC_V2: |
| 786 | model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True) |
| 787 | else: |
| 788 | |
| 789 | class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated] |
| 790 | arbitrary_types_allowed: bool = True |
| 791 | |
| 792 | def get_max_retries(self, max_retries: int) -> int: |
| 793 | if isinstance(self.max_retries, NotGiven): |
| 794 | return max_retries |
| 795 | return self.max_retries |
| 796 | |
| 797 | def _strip_raw_response_header(self) -> None: |
| 798 | if not is_given(self.headers): |
| 799 | return |
| 800 | |
| 801 | if self.headers.get(RAW_RESPONSE_HEADER): |
| 802 | self.headers = {**self.headers} |
| 803 | self.headers.pop(RAW_RESPONSE_HEADER) |
| 804 | |
| 805 | # override the `construct` method so that we can run custom transformations. |
| 806 | # this is necessary as we don't want to do any actual runtime type checking |
| 807 | # (which means we can't use validators) but we do want to ensure that `NotGiven` |
| 808 | # values are not present |
| 809 | # |
| 810 | # type ignore required because we're adding explicit types to `**values` |
| 811 | @classmethod |
| 812 | def construct( # type: ignore |
| 813 | cls, |
| 814 | _fields_set: set[str] | None = None, |
| 815 | **values: Unpack[FinalRequestOptionsInput], |
| 816 | ) -> FinalRequestOptions: |
| 817 | kwargs: dict[str, Any] = { |
| 818 | # we unconditionally call `strip_not_given` on any value |
| 819 | # as it will just ignore any non-mapping types |
| 820 | key: strip_not_given(value) |
| 821 | for key, value in values.items() |
| 822 | } |
| 823 | if PYDANTIC_V2: |
| 824 | return super().model_construct(_fields_set, **kwargs) |
| 825 | return cast(FinalRequestOptions, super().construct(_fields_set, **kwargs)) # pyright: ignore[reportDeprecated] |