libvirt-python: Extending libvirt-*override-api.xml?

Philipp Hahn hahn at
Mon Jul 27 07:47:00 UTC 2020


Am 25.07.20 um 23:45 schrieb Philipp Hahn:
> Am 27.04.20 um 15:44 schrieb Philipp Hahn:
>> I'm working on adding PEP 484 type hints
>> <> to the Python binding of
>> libvirt.
> I just opened a merge request
> <> for my
> code at <>.

While working on that I stumbled over two issues:

1. generator.skip_impl contained a list of the function names, which
were also defined in `libvirt-override-api.xml`. Adding an override
requires adding it in *two* locations.
it took the liberty to remove the list from and to extends
it by parsing "api.xml" where file="python*".

2. Historically "api*.xml" used "char *" to indicate some custom Python
type. Mapping this to "str" is obviously wrong, so I had to review them
and changed many of them to "Any" or more specific types with
As that information is both used to generate the low-level "C-to-Python"
mapping for "libvirtmod" but also the high-level Python module
"libvirt", changing `type` to something other then a C-type might breaks
the C-level wrapper.
Using a Python-type there which must be declared in "" is
also somehow cumbersome as there are many types which are used only once.
So I would like to extend this file with a new attribute like "pytype",
which then can be used to overwrite the type used by

> <function name='virDomainGetVcpus' file='python'>
>   <info>Extract information about virtual CPUs of domain, store it in info array and also in cpumaps.</info>
>   <return type='char *' info='None in case of error, returns a tuple of vcpu info and vcpu map.'/>
>   <return type='PyAny' info='None in case of error, returns a tuple of vcpu info and vcpu map.'/><!-- Tuple[List[Tuple[int, int, int, int]], List[Tutple[int, ...]]] -->
>   <arg name='domain' type='virDomainPtr' info='pointer to domain object, or NULL for Domain0'/>
> </function>

Is that okay?


More information about the libvir-list mailing list