|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH for-4.21] libxl: make gentypes.py compatible with Python older than 3.9
On 16.10.2025 13:45, Andrew Cooper wrote:
> 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 <jbeulich@xxxxxxxx>
>> ---
>> 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.
Yes, as said in the description.
> 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.
I first thought of doing something like this, but then didn't really see why
we would need such. If the prefix is anything else, the original construct
wouldn't work anyway (I expect an exception would be raised unless the incoming
string was itself consisting of only digits).
Jan
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |