pyhocon icon indicating copy to clipboard operation
pyhocon copied to clipboard

Assignment of variables with underscore in their name causes pyparsing exception

Open gafniguy opened this issue 2 years ago • 4 comments

With the following config file,

model{
    d_in = 3
    d_out = 2
}

I ran ConfigFactory.parse_file('./confs/test2.conf') and get an exception:

pyparsing.exceptions.ParseSyntaxException: , found '=' (at char 30), (line:3, col:11)

If I change d_out to e_out, or comment one of them out, or remove the underscore in at least one of their names, I will get no exception.

I get this with Python 3.11.3, Python 3.8.17 and pyparsing 3.1.0 and pyparsing 3.0.8

gafniguy avatar Jul 12 '23 13:07 gafniguy

Cam for the exact same problem and from the name of the variables I assume from the same repository :wink: I guess the best is to just rename the parameters at this point

GuillaumeLeclerc avatar Sep 20 '23 03:09 GuillaumeLeclerc

Actually pip install pyhocon==0.3.57 works

GuillaumeLeclerc avatar Sep 20 '23 03:09 GuillaumeLeclerc

Happens to me with this config

x = 1
y = 1

so the issue is probably not related to underscores or nestedness.

When I reorder the parameters:

y = 1
x = 1

it is parsed correctly. Changing the values to float solves the issue as well.

viktor-dolniik avatar Oct 09 '23 18:10 viktor-dolniik

That's a duplicate of https://github.com/chimpler/pyhocon/issues/324 and has been fixed by https://github.com/chimpler/pyhocon/pull/326 -> fixed in version 0.3.61: https://github.com/chimpler/pyhocon/releases/tag/0.3.61

=> Basically, variables with names starting with possible durations (ex: d_hello (d=day) or y_me (y=year) were incorrectly parsed if using "\n" with values, but fixed now

=> You can close this issue

pierresouchay avatar May 31 '24 20:05 pierresouchay