Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WeberJulian opened this issue Dec 27, 2021 · 6 comments

Comments

@WeberJulian
Copy link
Contributor

WeberJulian commented Dec 27, 2021

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)

@erogol
Copy link
Member

erogol commented Dec 28, 2021

@WeberJulian can you maybe give a code example of when it should raise an error and when it should work?

@erogol
Copy link
Member

erogol commented Feb 16, 2022

@WeberJulian ?

@WeberJulian
Copy link
Contributor Author

I'll add that tonight

@WeberJulian
Copy link
Contributor Author

I added the description @erogol

@erogol
Copy link
Member

erogol commented Mar 2, 2022

maybe not allowing a new attributes would be safer

@WeberJulian
Copy link
Contributor Author

maybe not allowing a new attributes would be safer

Agreed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants