GeezerVison is showing github.com — Refactor: use `Literal` in type hints · Issue #1670 · docarray/docarray
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 #1670DescriptionRight 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). Activitysrini047 commented on Jun 26, 2023 JoanFM commented on Jun 26, 2023 hey @srini047 ,
It would be great if you can take up this issue. bpshaver commented on Oct 23, 2023 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 commented on Oct 23, 2023 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 commented on Oct 24, 2023
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 commented on Oct 24, 2023 Yes, it would be nice to make sure there are other instances or if we can close this bpshaver commented on Oct 24, 2023 I believe these parameters are candidates for similar treatment:
-
audio_codec
-
audio_format
-
video_codec
But there may be more Reacted by Joan Fontanals JoanFM commented on Oct 24, 2023 They do seem nice candidates sure
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|