On 16/10/2025 12:22 pm, Jan Beulich wrote:
> removeprefix() was added only in 3.9. As long as the "jso_sub_" prefix is
> always going to be there anyway, switch to a less specific but more
> compatible construct.
>
> Fixes: f6c6f2679d49 ("libxl: libxl__object_to_json() to json-c")
> Signed-off-by: Jan Beulich <[email protected]>
> ---
> Sadly this is only the tip of the iceberg. Some minimum version of the
> json-c library is apparently needed for the toolstack to build, but no
> minimum version is being checked for.

Well, this is why we have release candidates, and a bug queue.

>
> --- a/tools/libs/light/gentypes.py
> +++ b/tools/libs/light/gentypes.py
> @@ -384,7 +384,7 @@ def libxl_C_type_gen_jso(ty, v, indent =
>          s += "int rc;\n"
>          sub_scope_object = "jso_sub_1"
>      else:
> -        sub_scope_object = "jso_sub_%d" % 
> (1+int(scope_object.removeprefix("jso_sub_")))
> +        sub_scope_object = "jso_sub_%d" % (1+int(scope_object[8:]))

This isn't quite an equivalent change.  You want:

def removeprefix(s, p): # Py < 3.9 compat
    if s.startswith(p):
        return s[len(p):]
    return s

at the top level somewhere, and to call removeprefix(scope_object,
"jso_sub_") here.

Sadly, because string is a builtin type, you can't make the 3.9 syntax
work on older versions of python by extending the string type.

~Andrew

Reply via email to