Giter Club home page Giter Club logo

Comments (3)

konradhalas avatar konradhalas commented on September 28, 2024 1

Hi @achennu, it's possible, here you go:

from dataclasses import dataclass
from dacite import from_dict, Config

@dataclass
class A:
    x: int
    y: int

@dataclass
class B:
    a: A
    is_cool: bool

@dataclass
class C:
    b: B
    count: int

C_config = Config(remap={'count': 'number'}, prefixed={'b.a': 'a_'})

DATA={
    'number': 30,
    'b': {
        'is_cool': False,
        'a_x': 30,
        'a_y': 55,
    }
}

from_dict(data_class=C, data=DATA, config=C_config)

You have right that I should improve documentation, there is no mention of "dot" syntax (b.a) at all. Let's leave this issue as open, so I will add a few words about it in the next release.

from dacite.

achennu avatar achennu commented on September 28, 2024

Ah I see, so that's the idea to have deeper nested structures handled. Thanks for the quick response.

Adding to the documentation is a good idea. Maybe a separate "When you really mean nested" section, as the current examples are short and to the point.

Do I understand it correctly that this "dot syntax" can be used for an of the Config settings?

A few examples that I'm wondering (aloud) about:

Config(remap={''b.a.x": "X"}) when the data dict contains "X" instead of "x".

Config(flattened=['b.a.']) can work?

from dacite.

konradhalas avatar konradhalas commented on September 28, 2024

Ah I see, so that's the idea to have deeper nested structures handled. Thanks for the quick response.

Your welcome :)

Do I understand it correctly that this "dot syntax" can be used for an of the Config settings?

Yep.

Config(remap={''b.a.x": "X"}) when the data dict contains "X" instead of "x".

It should work like that.

Config(flattened=['b.a.']) can work?

Config(flattened=['b.a']) - without trailing dot.

from dacite.

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.