Skip to content

giscanner: Modernize Python code

The minimum requirement in Meson is 3.8, so the Python 2 code is no longer needed. Additionally, we can take advantage of a few helpers to simplify code:

  • Designated initializers shorten the structs, and is now the recommendation in Python's docs.
  • PyModule_AddType simplifies adding types and is pretty much the same as the old REGISTER_TYPE macro. However, as this is 3.9+, I added a backport for 3.8's sake.
  • Use Py_RETURN_NONE to return None, and not worry about ref counts (it is now immortal in 3.12, so a ref isn't needed.)
  • Use METH_O flag for some methods; this removes the need to parse a tuple when there's only a single argument.
  • When using the "s" format with Py_BuildValue, a NULL value will automatically be converted to None, so drop the manual handling of that.

Also fix the exception handling (returning NULL should have set an exception and vice versa) and const-ness of string pointers.

Merge request reports