Skip to content

Interpolation of integers #156

Open
Open

Description

@sergeygrigorev

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

  1. hanschen commented on Feb 17, 2018

    @hanschen

    Sounds like a duplicate of #129.

  2. jhermann commented on Feb 18, 2018

    @jhermann
    Collaborator

    Related to #129, not a duplicate. It's the exact inverse.

  3. WeatherGod commented on Jun 2, 2018

    @WeatherGod

    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:

    foo = 1, 2, 3
    bar = This list: ${foo}
    

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

  4. robdennis commented on Jan 8, 2023

    @robdennis
    Member

    optimistically putting this in 5.1.0 assuming that the referenced PR helps me understand what's being requested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions