nats.py icon indicating copy to clipboard operation
nats.py copied to clipboard

KV's `Entry.operation` should have a literal type

Open kevinhikaruevans opened this issue 2 months ago • 0 comments

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 avatar May 31 '24 20:05 kevinhikaruevans