marcosschroh / dataclasses-avroschema

Generate avro schemas from python dataclasses, Pydantic models and Faust Records. Code generation from avro schemas. Serialize/Deserialize python instances with avro schemas.
https://marcosschroh.github.io/dataclasses-avroschema/
MIT License
218 stars 67 forks source link

Functional interface to AvroModel #747

Open hhoeflin opened 1 month ago

hhoeflin commented 1 month ago

Is your feature request related to a problem? Please describe. Currently using AvroModel requires inheriting from it. Providing a fully functional interface would allow to use the functionality for all dataclasses. Also, this way certain rather generic method-names (like validate) that could clash with other names, would not be on every instance.

Example of this design philosophy is "attrs" the project from which dataclasses were originally derived.

Describe the solution you'd like Looking through AvroModel, most methods seems to be classmethods - these could be extracted functionally and applied to the class passed as an argument. The instance-methods on AvroModel could be provided as functions applied to instances. The original AvroModel can get the same separately defined methods

Describe alternatives you've considered Not sure what alternative to use. Enforcing use of AvroModel in an inheritance -schema if I dont control all classes myself seems difficult.

Additional context None

marcosschroh commented 1 month ago

Hi @hhoeflin

It makes sense. I have to fix other things first before working on this. If you have any draft send it and we can take a look.