Skip to content

Fix type hinting issue with the Spinner class #260

@AbdelRahmanRahal

Description

@AbdelRahmanRahal

Very trivial issue with a very trivial fix.

Currently when attempting this valid code:

PHONE_SPINNER = Spinner(["📞 ", " 📞"], 100)

My linter screams this at me:

Argument of type "list[str]" cannot be assigned to parameter "frames" of type "str" in function "__init__"
  "list[str]" is not assignable to "str"

I checked the source code and I found this

        if isinstance(spinner.frames, str):
            uframes = spinner.frames

        # TODO (pavdmyt): support any type that implements iterable
        if isinstance(spinner.frames, (list, tuple)):
            # Empty ``spinner.frames`` is handled by ``Yaspin._set_spinner``
            if spinner.frames and isinstance(spinner.frames[0], bytes):
                uframes_seq = [to_unicode(frame) for frame in spinner.frames]
            else:
                uframes_seq = spinner.frames

So I recognise that it's a work in progress. However, as a very quick easy fix, I just added list[str] to the dataclass definition and it works fine, and doesn't break any code as far I could tell:

@dataclass
class Spinner:
    frames: str | list[str]
    interval: int

Let me know if this is worth it and I'll submit a PR with my fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions