pyhocon icon indicating copy to clipboard operation
pyhocon copied to clipboard

Is += working at all?

Open ws1088 opened this issue 3 years ago • 2 comments

test.conf:

foo {
    baz = ["a"]
    baz += "b"
}

code:

from pyhocon import ConfigFactory
spec = ConfigFactory.parse_file('./test.conf'))
print(spec)

output:

ConfigTree([('foo', ConfigTree([('baz', ' b')]))])

I thot += will concatenate...

ws1088 avatar Feb 15 '22 23:02 ws1088

Actually, it DOES concatenate... If you create the following config, the += would work... but NOT as intended:

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

Results in:

{
  "x": [
    1,
    2
  ],
  "d": {
    "x": [
      1,
      2,
      3,
      4
    ]
  }
}

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

Also, according to https://hocon-playground.herokuapp.com/, the += operator SHOULD NOT extend arrays, only append elements, which, ironically, pyhocon can't do.

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

thanks!

ws1088 avatar Oct 16 '22 03:10 ws1088