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

Make Abstract Classes with Typing for Serializers and Persisters #900

Open
tcyrus opened this issue Jan 11, 2025 · 0 comments
Open

Make Abstract Classes with Typing for Serializers and Persisters #900

tcyrus opened this issue Jan 11, 2025 · 0 comments

Comments

@tcyrus
Copy link

tcyrus commented Jan 11, 2025

I was looking into making a custom serializer and I was having trouble figuring out typing.

It's probably a good idea to make abstract classes with clear typing to make implementation easier.

Here's what I came up with:

import os
from abc import ABC, abstractmethod

from vcr.request import Request


class VcrPySerializer(ABC):
    @abstractmethod
    def deserialize(
        self,
        cassette_string: str
    ) -> dict:
        pass

    @abstractmethod
    def serialize(
        self,
        cassette_dict: dict
    ) -> str:
        pass


class VcrPyPersister(ABC):
    @abstractmethod
    @classmethod
    def load_cassette(
        cls,
        cassette_path: str | bytes | os.PathLike,
        serializer: VcrPySerializer
    )-> tuple[list[Request], list[bytes]]:
        pass

    @abstractmethod
    @staticmethod
    def save_cassette(
        cassette_path: str | bytes | os.PathLike,
        cassette_dict: dict,
        serializer: VcrPySerializer
    ) -> None:
        pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant