Skip to content

Support slices as fields #242

@victora-openai

Description

@victora-openai

Is your feature request related to a problem? Please describe.
It would be useful to support serialization and parsing of slice objects.

For example,

@dataclass
class Foo(DataClassMessagePackMixin):
    my_slice: slice
    slice_dict: dict[slice, int]  # Legal in Python 3.12

f = Foo(slice(0, 5), {slice(3,6,2): 4})
s = f.to_msgpack()
Foo.from_msgpack(s)

Describe the solution you'd like
Slices should be natively serializable and parsable. The snippet above should run.

Describe alternatives you've considered
It's possible to hand write a slice wrapper class. This is what I've been doing but as slice has become hashable in Python 3.12, it would be nice to not have to have a non-trivial wrapping and unwrapping layer.

Additional context
This could be a good first issue as slices can basically be represented as tuples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions