Skip to content

Draft: Add PEP-484 type annotations to generator and code

Philipp Hahn requested to merge pmhahn/libvirt-python:typing into master

As I had to touch almost every line I took the opportunity to also cleanup the code, as this simplified the task: I used mypy and flake8 a lot during development and every warning was distracting me from getting the thing done.

While doing that I also stumbled over lots of smaller problems and even bugs; they are at the start of the queue so feel free to fast-track them by only merging them or cherry-picking them.

This addresses python/typeshed#4310 by adding the type information into the library instead of carrying them as as separate files in a separate project. If you want to use the for previous information, look at my typeshed for libvirt.

This task was already announced once at https://patchew.org/Libvirt/cover.1587993402.git.hahn@univention.de/, which becomes obsolete with the pull-request.

  • there are some TODOs in c3b26fcc
  • maybe also create *.pyi stubs for libvirtmod*.so
  • extend libvirt-api.xml to return more specific Python types like List[int] - see comments
  • verify that my type annotations matches the actual returned data by calling each function from some (manually generated?) unit test file
Edited by Philipp Hahn

Merge request reports