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

Scope merging #37

Open
kenodegard opened this issue Jan 8, 2019 · 4 comments
Open

Scope merging #37

kenodegard opened this issue Jan 8, 2019 · 4 comments

Comments

@kenodegard
Copy link
Contributor

The following is valid however tomlkit isn't able to properly handle the dual scopes:

a.b.c = 12

[a.b]
d = 34
import tomlkit

doc = tomlkit.parse("""\
a.b.c = 12

[a.b]
d = 34
""")

# looking at the doc shows incomplete data
doc  # {'a': {'b': {'d': 34}}}

# retrieving data works
doc['a']['b']['c']  # 12

# modifying data fails
doc['a']['b']['c']  = 45
doc['a']['b']['c']  # 12

doc['a']['b']['d']  = 100
doc['a']['b']['d']  # 34
@eksortso
Copy link

eksortso commented Jan 8, 2019

Two important observations need to be made.

First, I ran the same code, and observed some other properties. This points to what could be considered a bug, but not the one you are thinking of. (I trimmed some extraneous blank lines.)

>>> doc
{'a': {'b': {'d': 34}}}

>>> doc['a']
{'b': {'d': 34}}

>>> doc['a']['b']  # Well, look at that! The c is back.
{'c': 12, 'd': 34}

>>> tomlkit.__version__
'0.5.3'

>>> sys.version_info
sys.version_info(major=3, minor=7, micro=1, releaselevel='final', serial=0)

Second, the document is not valid TOML, because the contents of a.b are split between two sections: the root section at the top, and the [a.b] section. You cannot define any table more than once, and the table a.b is defined when a.b.c = 12 is specified. As further proof, I used the toml library to parse the document, and got this error:

What? b already exists?{'b': {'c': 12}} (line 3 column 1 char 12)

The fact that tomlkit does not raise an error when parsing the document is the bug.

@kenodegard kenodegard mentioned this issue Jan 9, 2019
@kenodegard
Copy link
Contributor Author

Ok, I don't have an issue with this viewpoint I just can't find the TOML specs explicitly stating that implicit and explicit tables cannot be mixed. Just checked the ABNF and it doesn't prohibit it (but then the ABNF permits the same table to be defined multiple times and I know that's not permitted).

Just checked qTOML, they allow this.

@eksortso
Copy link

It was a matter of interpretation that wasn't explicitly specified in the standard, though the principle that you cannot define any table more than once is explicitly stated in v0.5.0.

The introduction of dotted keys opened up a can of worms; there is still interpretation to be applied, and standards language to be updated. Based on the strictest standards possible, the TOML in your example is invalid because the table a.b is introduced (implicitly by assigning a value to a.b.c) in the root table block before its own table block is introduced. I'm inclined to believe that the same restriction would apply under looser interpretations.

I've brought this up for debate under the TOML standard issue where these interpretations are being made.

By the way, the ABNF would consider the example well-formed, but it does nothing to identify whether it's valid.

@kenodegard
Copy link
Contributor Author

Ok, so I got caught up on the toml discussion, and I agree this isn't explicitly understood yet.

At least until this is better defined I feel the correct answer to this is to leave it up to the developer using tomlkit to decide which interpretation to allow in their case.

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