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

Load docstrings -> toml #3

Open
Trimatix opened this issue Sep 7, 2021 · 0 comments
Open

Load docstrings -> toml #3

Trimatix opened this issue Sep 7, 2021 · 0 comments

Comments

@Trimatix
Copy link
Owner

Trimatix commented Sep 7, 2021

This feature is mostly complete but tests fail under certain conditions when saving preceeding comments for structural variables (tables and arrays).

Variable is not ordering is not guaranteed. This is due to the TOML spec requiring that structural variables appear at the end of a document to resolve ambiguities in the variable heirarchy.
Since ordering is not guaranteed, and tomlkit does not explicitly know that preceeding comments are associated with variables, structural variables can be moved around during document rendering, with their preceeding comments left behind in undesirable locations in the document.

An unideal solution to this problem could make use of reflection, in a sense. A tomlkit document maintains two private fields:

  • _body: A list of (key (name), value) tuples
  • _map: A dictionary mapping a key (name) to the index of the key in _body.
    It may be possible to manipulate the rendering order of the document by manually moving the index of preceeding comments to just before the new table location. Depending on when reordering takes place, this may or may not be feasible.

there may be other easier solutions, or if all else fails, we can just manipulate the rendered string.

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

1 participant