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

unwrap() sometimes returns an internal tomlkit object #264

Closed
ghost opened this issue Jan 24, 2023 · 0 comments · Fixed by #266
Closed

unwrap() sometimes returns an internal tomlkit object #264

ghost opened this issue Jan 24, 2023 · 0 comments · Fixed by #266

Comments

@ghost
Copy link

ghost commented Jan 24, 2023

The tomlkit API returns internal classes such as tomlkit.items.Bool to represent parsed values.
There is also a method unwrap() which converts the parse tree into a plain Python dictionary-and-list representation.
(At least this is my understanding of unwrap(); please correct me if I am wrong.)

However in certain cases, the return value from unwrap() still contains tomlkit internal objects.

For example:

>>> import tomlkit
>>> doc = tomlkit.parse("[x.y] \n [p.q] \n [x.z] \n a = [true] \n")
>>> doc["x"]["z"]["a"][0]
True

>>> type(doc["x"]["z"]["a"][0])
<class 'tomlkit.items.Bool'>

>>> type(doc.unwrap()["x"]["z"]["a"][0])
<class 'tomlkit.items.Bool'>

I fully agree that the answer to my query type(doc["x"]["z"]["a"][0]) is tomlkit.items.Bool.
Since I am querying the tomlkit document structure, the query returns an internal tomlkit object to represent the boolean value.

However my last query type(doc.unwrap()["x"]["z"]["a"][0]) looks into the unwrapped data structure which should no longer contains tomlkit types. It should return an instance of bool, but I still get tomlkit.items.Bool.

This issue disappears if even a slight change is made to the TOML document.
It seems that the issue is related to the fact that unwrapping does not proceed past an instance of OutOfOrderTableProxy because it is not a subclass of tomlkit.items.Item.

This issue applies to the latest commit 6512eaa on master.
It doesn't seem to apply to the latest release v0.11.6.

I'm experimenting with a TOML fuzzer which revealed this issue. I guess most normal applications are not likely to hit this case, so I understand if this gets low priority. It still seems worthwhile to fix it though.

Edit: The first version of this issue report was accidentally a copy of another issue. Sorry, I pressed Enter at the wrong moment. Now fixed.

@ghost ghost changed the title unwrap() sometimes returns unwrap() sometimes returns an internal tomlkit object Jan 24, 2023
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

Successfully merging a pull request may close this issue.

0 participants