Skip to content

Add unwrap method to recursive convert to plain old python objects#187

Merged
frostming merged 22 commits into
python-poetry:masterfrom
syntapy:ppo
May 22, 2022
Merged

Add unwrap method to recursive convert to plain old python objects#187
frostming merged 22 commits into
python-poetry:masterfrom
syntapy:ppo

Conversation

@syntapy
Copy link
Copy Markdown
Contributor

@syntapy syntapy commented Apr 12, 2022

Adds methods to convert TOMLKit objects to plain python methods

Fixes #43

@syntapy syntapy marked this pull request as ready for review April 14, 2022 20:56
@syntapy syntapy changed the title [WIP] Add plain old python object conversion capabilities Add unwrap method to recursive convert to plain old python objects Apr 14, 2022
@syntapy syntapy marked this pull request as draft April 14, 2022 21:00
Comment thread tomlkit/container.py Outdated
Comment thread tomlkit/items.py Outdated
Comment thread tomlkit/items.py Outdated
@syntapy
Copy link
Copy Markdown
Contributor Author

syntapy commented Apr 27, 2022

Ok I think I just need to add tests for

  • container.Container
  • container.OutOfOrderTableProxy
  • items.Item
  • items.Integer
  • items.Float
  • items.Bool
  • items.DateTime
  • items.Date
  • items.Time
  • items.Array
  • items.AbstractTable
  • items.String
  • items.AoT
  • items.Null

@syntapy syntapy marked this pull request as ready for review April 28, 2022 12:21
@syntapy syntapy requested a review from frostming April 28, 2022 13:10
Comment thread tomlkit/container.py Outdated
Comment thread tomlkit/container.py Outdated
Comment thread tomlkit/container.py Outdated
@syntapy syntapy requested a review from frostming May 20, 2022 18:54
Comment thread tomlkit/items.py Outdated
def unwrap(self) -> str:
unwrapped = []
for t in self._body:
if is_tomlkit(t):
Copy link
Copy Markdown
Contributor

@frostming frostming May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a child of an array can't be a container. isinstance(t, Item) is enough for this case. But this also works

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@syntapy syntapy requested a review from frostming May 21, 2022 10:25
@syntapy syntapy requested a review from frostming May 22, 2022 03:35
@frostming frostming merged commit deac74d into python-poetry:master May 22, 2022
@syntapy
Copy link
Copy Markdown
Contributor Author

syntapy commented May 22, 2022

@frostming Is it OK if I make a PR to bump the version? If so which version? 0.11.0 or 0.10.3?

I am trying to use the version of tomlkit with these changes in a PR

capuanob pushed a commit to capuanob/tomlkit that referenced this pull request Mar 1, 2023
…ython-poetry#187)

* add as_ppo method for elementary types

* rename as_popo to unwrap; add recursive arg

* add unwrap methods to collection types + Null

* remove dangling 'def'

* Container loops through items() instead of _body

* add Integer and Item unit tests

* added passing tests for everything up to Array

* remove recursive option

* remove unused is_ppo function

* refactor Container unwrap to reuse code

* add AbstractTable test

* add string, null, and aot tests

* add test for Container

* type(..) to isinstance(..) in Container unwrap

* try/catch ensure v has unwrap in Container.unwrap

* replace 'type' with 'isinstance' in test_items.py

* refactor assert_is_ppo to pass only ppo type

* refactory test_document_is_a_dict to not call 'type'

* remove elementary_fail function

* minor change in Container unwrap method

* use isinstance not is_tomlkit in AoT.unwrap

* run pre-commit
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 this pull request may close these issues.

Function to convert everything to plain old python objects

2 participants