Skip to content

Type annotation of methods which are returning {api_endpoint}.call_with_http_info for asynchronous api is incorrect #2629

Open
@zhukovgreen

Description

@zhukovgreen

Describe the bug

For example in [1]:

    def create_spans_metric(
        self,
        body: SpansMetricCreateRequest,
    ) -> SpansMetricResponse:
        """Create a span-based metric.

        Create a metric based on your ingested spans in your organization.
        Returns the span-based metric object from the request body when the request is successful.

        :param body: The definition of the new span-based metric.
        :type body: SpansMetricCreateRequest
        :rtype: SpansMetricResponse
        """
        kwargs: Dict[str, Any] = {}
        kwargs["body"] = body

        return self._create_spans_metric_endpoint.call_with_http_info(**kwargs)

when the api client is async, the function returns coroutine. So the return type should be updated to

-    ) -> SpansMetricCreateRequest:
+    ) -> SpansMetricCreateRequest | Awaitable[SpansMetricCreateRequest]:

Type checkers are not happy about the current state

[1] https://github.com/DataDog/datadog-api-client-python/blob/master/src/datadog_api_client/v2/api/spans_metrics_api.py#L134-L150

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions