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

KV's Entry.operation should have a literal type #562

Open
kevinhikaruevans opened this issue May 31, 2024 · 0 comments
Open

KV's Entry.operation should have a literal type #562

kevinhikaruevans opened this issue May 31, 2024 · 0 comments
Labels
proposal Enhancement idea or proposal

Comments

@kevinhikaruevans
Copy link

kevinhikaruevans commented May 31, 2024

Proposed change

Minor thing, but it would be nice if in kv.py in the Entry dataclass, we instead used literals here for the operation field:

    @dataclass
    class Entry:
        """
        An entry from a KeyValue store in JetStream.
        """
        bucket: str
        key: str
        value: Optional[bytes]
        revision: Optional[int]
        delta: Optional[int]
        created: Optional[int]
        operation: Optional[str]

https://github.com/nats-io/nats.py/blob/main/nats/js/kv.py#L67-L78

I think it would be easier to use if it were:

operation: Optional[Literal[KV_DEL, KV_PURGE]]

Use case

It makes development easier if you're using an editor that autocompletes using type hints. It also makes it a little more self-documenting.

Contribution

Sure

@kevinhikaruevans kevinhikaruevans added the proposal Enhancement idea or proposal label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

No branches or pull requests

1 participant