Unpack dataclass as **dict?

I’ve got a class for storing data

@dataclass(slots=True, frozen=True)
class FeedSpecification:
    date: str
    feed_type: str
    feed_name: str
    engine: str

    def __iter__(self):
        return iter((self.date, self.feed_type, self.feed_name, self.engine))

    @property
    def cache_files(self) -> list[Path]:
        return cache_files(*self)

This code works great.

It would be more robust if I could unpack as **self instead of *self.
Is that possible? What would I need to define?

from dataclasses import asdict

**asdict(self)

Just to note, ** is not an operator, but part of the function-call syntax, so this only works for unpacking a mapping-valued function argument or element in a dict display, not as a stand-alone expression.

So it doesn’t exist then, does it?
A pity, but that does explain why I couldn’t find anything.
I decided to write a .as_dict() method, because I need the flexibility of a non-default dict constructor.
It works well enough, and perhaps it improves clarity compared with my original idea.

It does exists. You need to convince python that your dataclass is a mapping.

To do that, you need to implement keys and __getitem__:

from dataclasses import fields
class FeedSpecification:
    # ...
    def keys(self):
        return (f.name for f in fields(self))
    def __getitem__(self, item):
        return getattr(self, item)

You could even write that functionality as a mixin, so it can be re-used for different dataclasses. But IMO using asdict would be clearer to other readers of the code.