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

feat: add Generic(De)Serializer stub classes for generic formats #178

Merged
merged 2 commits into from
Aug 26, 2024

Conversation

aaraney
Copy link
Member

@aaraney aaraney commented Aug 26, 2024

Add GenericSerializer, GenericDeserializer, and GenericSerializerDeserializer abstract marker classes. ngen.init_config cannot support all formats under the sun, but with other tools like ngen.config_gen being aware of the abstractions present in ngen.init_config, these classes provide a common interface for generic data formats to interoperate. Beyond interfaces, the type's work as markers for other tools (e.g. isinstance check and change behavior).

ngen.init_config -- 0.0.7

Additions

  • Add GenericSerializer, GenericDeserializer, and GenericSerializerDeserializer abstract marker classes. Serializers and Deserializer must impliement the following methods respectively: to_file(self, f: pathlib.Path, *_) -> None, to_str(self, *_) -> str and from_file(cls, f: pathlib.Path, *_), from_str(cls, s: str, *_).

@aaraney aaraney self-assigned this Aug 26, 2024
@aaraney aaraney added enhancement New feature or request ngen.init_config Related to ngen.init_config package feat New software feature; Not build script / CI feature labels Aug 26, 2024
@aaraney
Copy link
Member Author

aaraney commented Aug 26, 2024

Lets merge this before #175. I am going to re-implement the work in #175 in terms of this.


@classmethod
@abstractmethod
def from_file(cls, p: Path, *_) -> Self:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewer, *_ effectively means that subclasses that add arguments must make them keyword only / optional. The goal is improve uniformity of implementations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add that note in the extended section of the doc string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can do that if you are adamant about it. I didn't add a comment b.c. the syntax and meaning are self evident (which I kind of like). Its not a super esoteric pattern, but to be fair, it is a newish pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too worried. I probably would literally have written it as "Note to self:" because I would forget in the future haha.

@aaraney aaraney force-pushed the feat-generic-serde branch 2 times, most recently from ffc7f99 to 777bc32 Compare August 26, 2024 19:30
@hellkite500 hellkite500 merged commit 6b35dd4 into NOAA-OWP:master Aug 26, 2024
13 checks passed
@aaraney aaraney deleted the feat-generic-serde branch August 26, 2024 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat New software feature; Not build script / CI feature ngen.init_config Related to ngen.init_config package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants