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

Code before:
            headers=headers,
            payload=payload,
            **kwargs,
        )

        if label is not None:
            request.user_data['label'] = label

        if session_id is not None:
            request.crawlee_data.session_id = session_id

        return request

    def get_query_param_from_url(self, param: str, *, default: str | None = None) -> str | None:
        """Get the value of a specific query parameter from the URL."""
        query_params = URL(self.url).query
        return query_params.get(param, default)

    @property
    def label(self) -> str | None:
        """A string used to differentiate between arbitrary request types."""
        return cast('UserData', self.user_data).label

    @property
    def session_id(self) -> str | None:
        """A string used to identify the bound session."""
        return self.crawlee_data.session_id

    @property
    def crawlee_data(self) -> CrawleeRequestData:
        """Crawlee-specific configuration stored in the `user_data`."""
        user_data = cast('UserData', self.user_data)
        if user_data.crawlee_data is None:
            user_data.crawlee_data = CrawleeRequestData()

        return user_data.crawlee_data

    @property
    def crawl_depth(self) -> int:
        """The depth of the request in the crawl tree."""
        return self.crawlee_data.crawl_depth

    @crawl_depth.setter
    def crawl_depth(self, new_value: int) -> None:
        self.crawlee_data.crawl_depth = new_value

    @property
    def state(self) -> RequestState | None:
        """Crawlee-specific request handling state."""
        return self.crawlee_data.state


Review comment (suggestion):
```suggestion
        """The ID of the bound session, if there is any."""
```

Code after:
            method=method,
            headers=headers,
            payload=payload,
            **kwargs,
        )

        if label is not None:
            request.user_data['label'] = label

        if session_id is not None:
            request.crawlee_data.session_id = session_id

        return request

    def get_query_param_from_url(self, param: str, *, default: str | None = None) -> str | None:
        """Get the value of a specific query parameter from the URL."""
        query_params = URL(self.url).query
        return query_params.get(param, default)

    @property
    def label(self) -> str | None:
        """A string used to differentiate between arbitrary request types."""
        return cast('UserData', self.user_data).label

    @property
    def session_id(self) -> str | None:
        """The ID of the bound session, if there is any."""
        return self.crawlee_data.session_id

    @property
    def crawlee_data(self) -> CrawleeRequestData:
        """Crawlee-specific configuration stored in the `user_data`."""
        user_data = cast('UserData', self.user_data)
        if user_data.crawlee_data is None:
            user_data.crawlee_data = CrawleeRequestData()

        return user_data.crawlee_data

    @property
    def crawl_depth(self) -> int:
        """The depth of the request in the crawl tree."""
        return self.crawlee_data.crawl_depth

    @crawl_depth.setter
    def crawl_depth(self, new_value: int) -> None:
        self.crawlee_data.crawl_depth = new_value

    @property
    def state(self) -> RequestState | None:
        """Crawlee-specific request handling state."""
        return self.crawlee_data.state