I'm trying to generate type stubs using pybind11-stubgen. However there are many errors in the generation process. Following the error message, I made some changes to the code: https://github.com/MeetWq/skia-python/tree/fix/pybind11
My changes mainly involve the following two aspects:
With the above changes, most of the errors that occurred during the execution of pybind11-stubgen have been resolved, but there are still some remaining errors:
pybind11_stubgen - [ ERROR] In skia.BBoxHierarchy.search : Invalid expression 'std::vector<int'
pybind11_stubgen - [ ERROR] In skia.BBoxHierarchy.search : Invalid expression ':allocator<int> >'
pybind11_stubgen - [ ERROR] In skia.ColorSpace.Deserialize : Can't find/import 'capsule'
pybind11_stubgen - [ ERROR] In skia.ColorSpace.writeToMemory : Can't find/import 'capsule'
pybind11_stubgen - [ ERROR] In skia.GrBackendSemaphore.MakeVk : Can't find/import 'capsule'
pybind11_stubgen - [ ERROR] In skia.GrBackendSemaphore.vkSemaphore : Can't find/import 'capsule'
pybind11_stubgen - [ ERROR] In skia.GrBackendTexture.setMutableState : Invalid expression 'skgpu::MutableTextureState'
pybind11_stubgen - [ ERROR] In skia.GrContext_Base.threadSafeProxy : Can't find/import 'GrContextThreadSafeProxy'
pybind11_stubgen - [ ERROR] In skia.GrDirectContext.setBackendRenderTargetState : Invalid expression 'skgpu::MutableTextureState'
pybind11_stubgen - [ ERROR] In skia.GrDirectContext.setBackendTextureState : Invalid expression 'skgpu::MutableTextureState'
pybind11_stubgen - [ ERROR] In skia.GrVkImageInfo.fSharingMode. : Can't find/import 'VkSharingMode'
pybind11_stubgen - [ ERROR] In skia.GrVkImageInfo.fSharingMode. : Can't find/import 'VkSharingMode'
pybind11_stubgen - [ ERROR] In skia.MemoryStream.__init__ : Can't find/import 'capsule'
pybind11_stubgen - [ ERROR] In skia.MemoryStream.getAtPos : Can't find/import 'capsule'
pybind11_stubgen - [ ERROR] In skia.Point.Offset : Invalid expression 'std::vector<SkPoint'
pybind11_stubgen - [ ERROR] In skia.Point.Offset : Invalid expression ':allocator<SkPoint> >'
pybind11_stubgen - [ ERROR] In skia.Point.Offset : Invalid expression 'std::vector<SkPoint, std::allocator<SkPoint> >'
pybind11_stubgen - [ ERROR] In skia.Shaders.Blend : Can't find/import 'SkBlender'
pybind11_stubgen - [ ERROR] In skia.Stream.getMemoryBase : Can't find/import 'capsule'
pybind11_stubgen - [ ERROR] In skia.Surface.AsyncReadResult.data : Can't find/import 'capsule'
pybind11_stubgen - [ ERROR] In skia.Surface.WrapBackendRenderTarget : Invalid expression 'void (void*)'
pybind11_stubgen - [ ERROR] In skia.Surface.WrapBackendRenderTarget : Can't find/import 'capsule'
pybind11_stubgen - [ ERROR] In skia.Surface.flush : Invalid expression 'skgpu::MutableTextureState'
pybind11_stubgen - [WARNING] Raw C++ types/values were found in signatures extracted from docstrings.
Please check the corresponding sections of pybind11 documentation to avoid common mistakes in binding code:
- https://pybind11.readthedocs.io/en/latest/advanced/misc.html#avoiding-cpp-types-in-docstrings
- https://pybind11.readthedocs.io/en/latest/advanced/functions.html#default-arguments-revisited
pybind11_stubgen - [ INFO] Terminating due to previous errors
Since I'm not familiar with either pybind11 or skia, I'm not sure how to fix them. The above errors show some problems in skia-python, such as skgpu::MutableTextureState is not defined with py::class_.
Can you help with these errors? Should I contribute these changes to the repository?
I'm trying to generate type stubs using
pybind11-stubgen. However there are many errors in the generation process. Following the error message, I made some changes to the code: https://github.com/MeetWq/skia-python/tree/fix/pybind11My changes mainly involve the following two aspects:
split pybind declarations and definitions


According to the document of pybind11, docstrings are generated at the time of the declaration, e.g. when
.def(...)is called. At this point parameter and return types should be known to pybind11. By spliting thepy::class_constructors and.def(...)definitions, some C++ type names in the docstring were replaced:before:
after:
manually specify preview of default arguments


According to the document of pybind11, the “preview” of the default argument in the function signature is generated using the object’s
__repr__method. If not available, the signature may not be very helpful. We can manually specify the human-readable preview of the default argument using thearg_vnotation:before:
after:
With the above changes, most of the errors that occurred during the execution of
pybind11-stubgenhave been resolved, but there are still some remaining errors:Since I'm not familiar with either
pybind11orskia, I'm not sure how to fix them. The above errors show some problems inskia-python, such asskgpu::MutableTextureStateis not defined withpy::class_.Can you help with these errors? Should I contribute these changes to the repository?