Repository: apify/crawlee-python
File: src/crawlee/_request.py (Python)

Code before:
    def __delitem__(self, key: str) -> None:
        del self.__pydantic_extra__[key]

    def __iter__(self) -> Iterator[str]:  # type: ignore[override]
        yield from self.__pydantic_extra__

    def __len__(self) -> int:
        return len(self.__pydantic_extra__)

    def __eq__(self, other: object) -> bool:
        if isinstance(other, BaseModel):
            return super().__eq__(other)

        if isinstance(other, dict):
            return self.model_dump() == other

        return NotImplemented


user_data_adapter = TypeAdapter(UserData)


class RequestOptions(TypedDict):
    """Options that can be used to customize request creation.

    This type exactly matches the parameters of Request.from_url() method.
    """

    url: Required[str]
    method: NotRequired[HttpMethod]
    headers: NotRequired[HttpHeaders | dict[str, str] | None]
    payload: NotRequired[HttpPayload | str | None]
    label: NotRequired[str | None]
    unique_key: NotRequired[str | None]
    id: NotRequired[str | None]
    keep_url_fragment: NotRequired[bool]
    use_extended_unique_key: NotRequired[bool]
    always_enqueue: NotRequired[bool]
    user_data: NotRequired[dict[str, JsonSerializable]]
    no_retry: NotRequired[bool]


@docs_group('Data structures')
class Request(BaseModel):
    """Represents a request in the Crawlee framework, containing the necessary information for crawling operations.

    The `Request` class is one of the core components in Crawlee, utilized by various components such as request
    providers, HTTP clients, crawlers, and more. It encapsulates the essential data for executing web requests,
    including the URL, HTTP method, headers, payload, and user data. The user data allows custom information
    to be stored and persisted throughout the request lifecycle, including its retries.


Review comment (suggestion):
```suggestion
    This type exactly matches the parameters of `Request.from_url` method.
```

Code after:
    def __delitem__(self, key: str) -> None:
        del self.__pydantic_extra__[key]

    def __iter__(self) -> Iterator[str]:  # type: ignore[override]
        yield from self.__pydantic_extra__

    def __len__(self) -> int:
        return len(self.__pydantic_extra__)

    def __eq__(self, other: object) -> bool:
        if isinstance(other, BaseModel):
            return super().__eq__(other)

        if isinstance(other, dict):
            return self.model_dump() == other

        return NotImplemented


user_data_adapter = TypeAdapter(UserData)


class RequestOptions(TypedDict):
    """Options that can be used to customize request creation.

    This type exactly matches the parameters of `Request.from_url` method.
    """

    url: Required[str]
    method: NotRequired[HttpMethod]
    headers: NotRequired[HttpHeaders | dict[str, str] | None]
    payload: NotRequired[HttpPayload | str | None]
    label: NotRequired[str | None]
    unique_key: NotRequired[str | None]
    id: NotRequired[str | None]
    keep_url_fragment: NotRequired[bool]
    use_extended_unique_key: NotRequired[bool]
    always_enqueue: NotRequired[bool]
    user_data: NotRequired[dict[str, JsonSerializable]]
    no_retry: NotRequired[bool]


@docs_group('Data structures')
class Request(BaseModel):
    """Represents a request in the Crawlee framework, containing the necessary information for crawling operations.

    The `Request` class is one of the core components in Crawlee, utilized by various components such as request
    providers, HTTP clients, crawlers, and more. It encapsulates the essential data for executing web requests,
    including the URL, HTTP method, headers, payload, and user data. The user data allows custom information
    to be stored and persisted throughout the request lifecycle, including its retries.