chimpler / pyhocon

HOCON parser for Python
Apache License 2.0
502 stars 118 forks source link

WIP: #281: Fixes for lists expansion operator (`+=`) #290

Open USSX-Hares opened 2 years ago

USSX-Hares commented 2 years ago

Root Casuse

Actually, the += operator took the HOCON definition too literally. When the x += y was met, it created a substitution for x. Then, when the entire config is read, that substitution is applied at the exact name x. However, if x was inside a dict object, the x would not be resolved.

Changes

ToDo:

coveralls commented 2 years ago

Coverage Status

Coverage decreased (-1.9%) to 94.294% when pulling aa133cf9ca212dcea3f582f85f817448e692a70b on USSX-Hares:bug/281-expand-list-fixes into be660deb6d6a5a175d384792e208fd39986758ea on chimpler:master.

USSX-Hares commented 2 years ago

I've found that pyhocon's implementation of the operator += diverges from the HOCON standard: in HOCON, += (1) can only be applied to arrays and (2) can only append elements to arrays, not extend arrays with the arrays.

According to https://hocon-playground.herokuapp.com/, the following configuration:

d {
    x = [1,2]
    x += [3,4]
}

resolves into the following:

d {
    x=[
        1,
        2,
        [
            3,
            4
        ]
    ]
}

@darthbear, what do you think?