pyhocon icon indicating copy to clipboard operation
pyhocon copied to clipboard

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

Open USSX-Hares opened this issue 3 years ago • 2 comments

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

  • Added tests covering broken operator behavior
  • The += operator now creates a smarter substitution

ToDo:

  • [ ] Check other conditions when it may fail
  • [ ] (?) Resolve += in-place?

USSX-Hares avatar Sep 25 '22 23:09 USSX-Hares

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.

coveralls avatar Sep 25 '22 23:09 coveralls

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?

USSX-Hares avatar Sep 25 '22 23:09 USSX-Hares