Skip to content

[feature request] Warning when unexpected key is loaded but not present in class #29

@WeberJulian

Description

@WeberJulian

Here is an toy scenario where it would be nice to have a warning

from dataclasses import dataclass
from coqpit import Coqpit

@dataclass
class SimpleConfig(Coqpit):
    val_a: int = 10
    val_b: int = None

if __name__ == "__main__":
    config = SimpleConfig()

    tmp_config = config.to_dict()
    tmp_config["unknown_key"] = "Ignored value"
    config.from_dict(tmp_config)
    print(config.to_json())

There the value of config.to_json() is

{
    "val_a": 10,
    "val_b": null
}

Which is expected behaviour, but we should get a warning that some keys were ignored (IMO)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions