Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

Refactor: use Literal in type hints #1670

Open

Description

@JohannesMessner

Right now we don't really use Literal types anywhere, but we should.
For example, see the following signature:

    @classmethod
    def from_bytes(
        cls: Type[T],
        data: bytes,
        protocol: str = 'protobuf',
        compress: Optional[str] = None,
    ) -> T:
        """Build Document object from binary bytes

        :param data: binary bytes
        :param protocol: protocol to use. It can be 'pickle' or 'protobuf'
        :param compress: compress method to use
        :return: a Document object
        """

Here, protocol can only be 'pickle' or 'protobuf', so Literal['pickle', 'protobuf'] would be the most suitable type hint.
Changing that will require multiple other changes in order to keep mypy happy, since other code relies on protocol being str.

This issue is about adjusting the above, and identifying and fixing other similar instances (if they exists).

Activity

  1. converted this from a draft issue on Jun 26, 2023
  2. srini047 commented on Jun 26, 2023

    @srini047
    Contributor

    Hey, @JohannesMessner I would like to work on this issue.

  3. JoanFM commented on Jun 26, 2023

    @JoanFM
    Member

    hey @srini047 ,

    It would be great if you can take up this issue.

  4. moved this from Todo/Bug to In Progress in DocArray backlogon Jul 5, 2023
  5. moved this from In Progress to In progress by community in DocArray backlogon Jul 5, 2023
  6. bpshaver commented on Oct 23, 2023

    @bpshaver
    Contributor

    Is protobuf-array also a possible value for protocol in the intended context? (If not... maybe the parameter name protocol should be used to refer to two different things.)

  7. bpshaver commented on Oct 23, 2023

    @bpshaver
    Contributor

    Opened a PR.

    I'm in favor of an enum over a Literal consisting of different strings, but I can see how the latter is easier for end users. I can seek out other instances of this same issue if this PR looks good.

  8. JohannesMessner commented on Oct 24, 2023

    @JohannesMessner
    MemberAuthor

    I can seek out other instances of this same issue if this PR looks good.

    The PR looks good, helping us with further instances of this problem would be great!

  9. JoanFM commented on Oct 24, 2023

    @JoanFM
    Member

    Yes, it would be nice to make sure there are other instances or if we can close this

  10. bpshaver commented on Oct 24, 2023

    @bpshaver
    Contributor

    I believe these parameters are candidates for similar treatment:

    • audio_codec

    • audio_format

    • video_codec

    But there may be more

  11. JoanFM commented on Oct 24, 2023

    @JoanFM
    Member

    They do seem nice candidates sure

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

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions