Open
Labels
Description
Assume this config:
# config
a = 1
b = 2
c = "$a + $a = $b"
# spec
a = integer
b = integer
c = string
It finds that c matches with Template regex, tries to substitute a into c, finds a and tries to match Template regex with a that is integer because of spec applied. So, it raises TypeError: expected string or bytes-like object.
Activity
hanschen commentedon Feb 17, 2018
Sounds like a duplicate of #129.
jhermann commentedon Feb 18, 2018
Related to #129, not a duplicate. It's the exact inverse.
WeatherGod commentedon Jun 2, 2018
Actually, I suspect this is exactly the same issue. The problem is that the configspec turned the values into non-strings. But the string interpolation stage only supports string-like inputs and does no coercion at all.
In fact, you don't even need a configspec to cause this problem:
is sufficient to cause the issue if
list_values=True.I want to fix this problem for a work project. I don't think the right thing to do is to perform coercion. Rather, perhaps the original strings could be stored along side the stored values and those values are used for string interpolation instead. Maybe fall back to using
str()on the value in the case where there is no stored string representation (such as when the configobj didn't come from a string buffer or the user sets a non-string value after construction).robdennis commentedon Jan 8, 2023
optimistically putting this in 5.1.0 assuming that the referenced PR helps me understand what's being requested