sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
228 stars 45 forks source link

Crash while parsing a submodule sharing parent's name #159

Closed MironMA closed 10 months ago

MironMA commented 10 months ago

Hi!

I recently updated to 2.3 of pybind11-stubgen, but I've encountered a crash while running on the same code. I decided to go to the bottom of it and found the following.

I have a python module importing some pybind11 module sharing the same name as it's parent, thus the module's name is my_module.my_module. When parsed, the method FixCurrentModulePrefixInTypeNames._strip_current_module in fix.py will, as it's name says, remove the name my_module from my_module.my_module origin, which is my_module. At this point, the stripped origin becomes an empty string, then _get_parent_module returns None on this invalid module name, and finally report_error will fail to report the error, trying to print error.name[0] on an empty string error.name.

Removing the striping methods seems to work, but I guess it was there to address another kind of input.

What would be your opinion on this? What are the constrains while trying to fix fix.py?

MironMA commented 10 months ago

Turns out that it was an error on my side, doing a circular import. Good luck with this great project!