This is a more general, follow-on ticket to #6349 which focuses on extension modules built with `pybind11`.