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

Convert ExportData to standard Python class #914

Open
mferrera opened this issue Dec 12, 2024 · 0 comments
Open

Convert ExportData to standard Python class #914

mferrera opened this issue Dec 12, 2024 · 0 comments

Comments

@mferrera
Copy link
Collaborator

mferrera commented Dec 12, 2024

Currently this class is implemented as dataclass. Dataclasses are very useful as containers of data (hence the name) so that you can, for example, pass a class around rather than a dict, use dot access to its values, and easily print it out to see its values, etc. They are not the optimal choice when dealing with complicated state, implementing more than few methods to operate on that state, having required or optional arguments, etc.

It's very useful to handle these things at initialization, rather than after with a __post_init__ method, and is a lot more easy to understand as well. When lots of logic is ending up in a __post_init__() method it indicates that we should just use a standard class instead.

The current keyword argument semantics can be retained like so:

def __init__(self, *, config, some_arg = None, ...) -> Self

Here the ordering is not important when creating the class, config will be required to be provided as ExportData(config=...), and some_arg is optional. An empty initialization will cause ExportData() to raise a TypeError.

This gives a better sense of what the user is providing as input, how to validate or transform that input before it's set to a field. It also allows for state updates to be more transparent, immutable to users, and for methods to have better insight into what the state of any given variable is.

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