Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: use Literal in type hints #1670

Open
JohannesMessner opened this issue Jun 26, 2023 · 8 comments · May be fixed by #1680
Open

Refactor: use Literal in type hints #1670

JohannesMessner opened this issue Jun 26, 2023 · 8 comments · May be fixed by #1680
Labels
area/typing good-first-issue Suitable as your first contribution to DocArray!

Comments

@JohannesMessner
Copy link
Member

JohannesMessner commented Jun 26, 2023

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).

@JohannesMessner JohannesMessner added good-first-issue Suitable as your first contribution to DocArray! area/typing labels Jun 26, 2023
@srini047
Copy link
Contributor

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

@JoanFM
Copy link
Member

JoanFM commented Jun 26, 2023

hey @srini047 ,

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

@srini047 srini047 linked a pull request Jun 28, 2023 that will close this issue
@bpshaver
Copy link
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.)

@bpshaver
Copy link
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.

@JohannesMessner
Copy link
Member Author

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!

@JoanFM
Copy link
Member

JoanFM commented Oct 24, 2023

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

@bpshaver
Copy link
Contributor

bpshaver commented Oct 24, 2023

I believe these parameters are candidates for similar treatment:

  • audio_codec

  • audio_format

  • video_codec

But there may be more

@JoanFM
Copy link
Member

JoanFM commented Oct 24, 2023

They do seem nice candidates sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/typing good-first-issue Suitable as your first contribution to DocArray!
Projects
Status: In progress by community
Development

Successfully merging a pull request may close this issue.

4 participants