Closed hbmartin closed 5 years ago
Not at the moment but it shouldn't be too hard to implement. I'll look into it.
Another great feature would be an option to generate stubs for a package, like stubgen does it.
@doblak On a first glance, the parameters in the "Specifying what to stub" section on that stubgen page make sense for pygenstub too. I'll try to stick to that interface. Thanks.
I've implemented a first attempt at this. Example use:
pygenstub -m xml -o out
There are some rough edges that need fixing. It also needs testing and documentation. Multiple input files and directories are also supported now.
Sorry, a change about usage to make it more like stubgen. Usage examples are now:
pygenstub foo.py
pygenstub foo.py bar.py baz.py
pygenstub foodir
pygenstub -m string -o out
pygenstub -p xml -o out
pygenstub -p xml.dom -o out
And combinations of these.
@uyar this is amazing, thank you!!! 👏 I noticed on some packages I am getting "cannot handle package" error, what does this mean? Again, so much appreciation!
@tinder-haroldmartin Thank you! About the error, it's a catch-all case if anything goes wrong. I don't know much about what could go wrong yet. But you can try running with --debug
to see the exception. If it says that it cannot find __path__
maybe trying with -m
instead of -p
could help.
I've realized that implementing stubgen-like behavior (using Any
where there's no signature information) could be within reach. I'm not sure whether it's worth it, though. It feels like reimplementing stubgen; and pygenstub was meant for processing signatures, not as a general template generator.
@uyar I suppose my particular use case might be edge-y. I'm using the ide/app Pythonista to write Python code for iOS. It has some builtin libs for providing access to iOS calls and I've been writing interface stubs slowly by hand. I can't use stubgen because it requires a compiled C library (for reading the AST) and Pythonista can't install C libs.
I tried with -m
instead, which runs successfully, but only produces a stub showing some top level imports.
@tinder-haroldmartin This is expected behavior at the moment. pygenstub will ignore the parts that don't have signatures in their docstrings. I'll see if I can add support for producing generic stubs.
@tinder-haroldmartin OK, I have some implementation of generic stub generation in the repo. It could be improved, I guess. Then again, it could be totally buggy and useless. To activate it, use --generic
:
pygenstub -p urllib -o out --generic
This is brilliant! Exactly what I hoped for. My deepest thanks for your hard work!
Can this be used to generate stubs for a module?