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

Enhancement: Implement Object Mapping Using Pydantic / Msgspec #128

Open
BoggerByte opened this issue Feb 20, 2024 · 2 comments · May be fixed by #129 or #161
Open

Enhancement: Implement Object Mapping Using Pydantic / Msgspec #128

BoggerByte opened this issue Feb 20, 2024 · 2 comments · May be fixed by #129 or #161
Labels
enhancement New feature or request

Comments

@BoggerByte
Copy link

Enhancement description

There are a lot of hardcoded values used for object mapping for models (from_dict method) within the library. For instance, this is the Section class mapping from dict:

@dataclass
class Section:
    id: str
    name: str
    order: int
    project_id: str

    @classmethod
    def from_dict(cls, obj):
        return cls(
            id=obj["id"],
            name=obj["name"],
            order=obj["order"],
            project_id=obj["project_id"],
        )

I suggest allowing some third-party object mapping library like pydantic or msgspec to handle this logic.

The problem it solves

The current implementation with hardcoded values in the from_dict method makes the code less maintainable and flexible. By integrating a third-party library for object mapping, we can improve readability, maintainability, and reduce the chances of errors.

Alternatives

Currently, we could continue with the hardcoded approach, but it may lead to increased complexity and maintenance overhead as the project grows. Alternatively, we can manually implement more flexible object mapping methods, but this may also introduce additional boilerplate code and potential errors.

Use case / screenshots

N/A

Additional information

Integrating a third-party library for object mapping will not only streamline the codebase but also potentially introduce additional features such as validation and serialization, which can enhance the robustness and usability of the library.

@BoggerByte BoggerByte added the enhancement New feature or request label Feb 20, 2024
@BoggerByte BoggerByte changed the title Use pydantic / msgspec for data decoding Enhancement: Implement Object Mapping Using Pydantic / Msgspec Feb 20, 2024
@BoggerByte BoggerByte linked a pull request Feb 20, 2024 that will close this issue
3 tasks
@BoggerByte
Copy link
Author

I've submitted a PR addressing the issue! #129 🎉
Check it out and let me know your thoughts! Your feedback is highly valued.

@lefcha lefcha linked a pull request Feb 21, 2025 that will close this issue
@BoggerByte
Copy link
Author

As mentioned in #161 pydantic is a major dependency. So I've decided to use dataclasses_json instead. Here's a new PR #163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant