chimpler / pyhocon

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

Is += working at all? #281

Closed ws1088 closed 1 year ago

ws1088 commented 2 years ago

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...

USSX-Hares commented 2 years ago

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 commented 2 years ago

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

ws1088 commented 1 year ago

thanks!