Git Product home page Git Product logo

Comments (2)

ramonhagenaars avatar ramonhagenaars commented on August 17, 2024

Hi @aquamatthias,

I tested your code and it does indeed not render c and d. What I found however, was that it had nothing to do with Optional or Union, but with there being default values. jsons considers Foo.c and Foo.d as class attributes, because c and d both actually exist on Foo and hold a value:

>>> Foo.d
'test'

Therefore they get skipped when strip_class_variables=True. I'm not so sure what to think of this... technically, jsons is right, because c and d can be accessed on the class. But on a dataclass, it is not unusual to use default values for instance attributes like you do. 🤔

Anyhow, would using strip_attr be of any help in your case?

jsons.dump(foo, strip_attr=("static",))

from jsons.

aquamatthias avatar aquamatthias commented on August 17, 2024

Hey @ramonhagenaars. Thanks for the explanation - I was unaware of the implication with the default value. I think the workaround is possible for cases where the class variables are known upfront. From a pythonic/library point of view, I still think the test above should work - this is what I would expect without thinking about it.

from jsons.

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.