Coder Social home page Coder Social logo

Comments (4)

biqqles avatar biqqles commented on August 30, 2024 1

Sorry, I misunderstood because of the simplicity of your example.

So potentially the additional functionality would be to add an internals arg to as_dict to accomplish this?

Yes, I would do exactly this.

from dataclassy.

yesthesoup avatar yesthesoup commented on August 30, 2024 1

No worries - I could have shared all of my current huge dataclasses but it's a lot to type out, was easier at first to share a simple example.

Thanks for the feedback! I'll see if I can fit time to make this change and submit a PR soon.

from dataclassy.

biqqles avatar biqqles commented on August 30, 2024

values also returns a dict (but not recursively) and accepts an internals parameter, which defaults to False. In your simple example, I think it's what you want.

as_dict is more for serialising an entire nested data structure to a "simpler" format that can be e.g. dumped to JSON. That doesn't mean it shouldn't have an internals argument though. That could be added (and for as_tuple as well).

I would rather have an extra argument than these functions to introspect the class because it gives the user more control (you could easily want some fields to not show up in the repr, but still be important to serialise).

from dataclassy.

yesthesoup avatar yesthesoup commented on August 30, 2024

Right - to use values I think I would have to build a custom recursing function to reproduce as_dict though, as the dataclasses I am working with are large nested dataclass "types".

It is the exact functionality you mention that I am primarily using them for in my project:

serialising an entire nested data structure to a "simpler" format that can be e.g. dumped to JSON

but using an internal variable to keep track of various subclasses of component dataclasses. I can share an example if this doesn't make sense of course.

So potentially the additional functionality would be to add an internals arg to as_dict to accomplish this?

from dataclassy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.