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

Where does #metadata# go? #85

Open
evetion opened this issue Feb 16, 2023 · 6 comments
Open

Where does #metadata# go? #85

evetion opened this issue Feb 16, 2023 · 6 comments

Comments

@evetion
Copy link

evetion commented Feb 16, 2023

I'm using from_toml, and it would be nice to be able to override construction with the path of the toml file (e.g. when paths in the TOML are relative to the TOML itself). Could it be passed in a user defined from_dict() method?

Otherwise it's unclear to me where the #metadata# key ends up in from_dict.

@Roger-luo
Copy link
Owner

No, it only appears in from_toml, I haven't thought much how this information be propagated into from_dict, so if you need to preprocess something you should overload from_toml, could you elaborate on your use cases a bit more? for example by providing an example

@evetion
Copy link
Author

evetion commented Feb 16, 2023

So somewhere in from_dict the key #metadata# is ignored? I'd assumed it would throw InvalidKeyError?

could you elaborate on your use cases a bit more

An example would be a toml:

path = "relative.file"  # relative path

Such a path can be absolute or relative. In case it's relative, it can be assumed it's relative to the TOML file itself. However, this foldername is not accessible on construction (or when overloading from_dict(::Type{MyType}, ::Type{SystemPath}, s)), but is precisely what you pass in d["#metadata#"]["dir"] in from_toml.

@Roger-luo
Copy link
Owner

Yes, it's ignored by validation, this is a special field to give you access to that

for key in keys(d)

@Roger-luo
Copy link
Owner

I think this field should always be available if you construct using from_toml etc

@evetion
Copy link
Author

evetion commented Feb 16, 2023

Ok, but how would one access the #metadata# key? Naming such an field in my custom type is not directly possible.

@Roger-luo
Copy link
Owner

ah, you need to overload your custom from_dict, it will not appear in your custom type by default, it's a meta info only used by the parsers

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

No branches or pull requests

2 participants