Skip to content

Type session.SearchResults, returned by session.search has an incorrect type hint #409

Description

@toluschr

Hi,

For several months now, tidal-dl-ng and derivatives have had a broken search. Today, I decided to investigate and (surprisingly quickly) narrowed it down to what seems like a bug in the python-tidal project. For reference, tidal-dl-ng threw this exception:

  File "tidal_dl_ng/helper/tidal.py", line 130, in search_results_all
    result[key] += value
TypeError: unsupported operand type(s) for +=: 'Track' and 'Track'

Unlike specified in tidalapi.session.SearchResults [1], tidalapi.session.search no longer returns the topHit property as an Optional[List[Any]], but instead as an Optional[Any]. I don't know if this was intended or is the result of a change to the internal Tidal-Api.

Making tidalapi.session.search wrap result["top_hit"] in a list fixes the issue [2].

        # Find the type of the top hit so we can parse it
        if json_obj["topHit"]:
            top_type = json_obj["topHit"]["type"].lower()
            parse = self.convert_type(top_type, output="parse")
            result["top_hit"] = self.request.map_json(
                json_obj["topHit"]["value"], cast(Callable[..., Any], parse)
            )
            if not isinstance(result["top_hit"], list): result["top_hit"] = [result["top_hit"]] # the fix

I hope this helps resolve the issue. I'm not sure what the desired behavior is and if adding my little hack would be fine for you.

[1] https://github.com/EbbLabs/python-tidal/blob/main/tidalapi/session.py#L207-L213
[2] https://github.com/EbbLabs/python-tidal/blob/main/tidalapi/session.py#L820-L826

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions