Fix/recursive jpackage stubs
Addresses the case of stubs not existing for parent packages for the JPackage case.
For example, previously when generating stubs for java.util.zip
with something like:
python -m stubgenj java.util.zip
The stubs at java-stubs/__init__.pyi
would be empty, but in practice they need to include the java.__module_protocol__
implementation along the lines of:
import java.util
import typing
class __module_protocol__(typing.Protocol):
# A module protocol which reflects the result of ``jp.JPackage("java")``.
util: java.util.__module_protocol__
In this example, we would then need a similar stubfile for the java-stubs/util/__init__.pyi
file, which would again provide a __module_protocol__
for the zip
package.
What this change doesn't do is automatically "promote" stub __module__protocol__
s for items not explicitly mentioned. The example above results in stubs being generated for a bunch of other modules (e.g. java.util.spi
) but this __module_protocol__
is not added to java.util
(unless explicitly asked for). I believe this is consistent with what we are trying to achieve whereby we only give suggestions for packages that are explicitly enabled (and all of their children recursively). I didn't add tests to this end, and believe it would be tricky with the current test infrastructure.