-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add recursive and lenient modes to stub generation #2183
Conversation
Thanks, these are good ideas. Can you fix the test?
…--Guido (mobile)
|
@@ -574,6 +575,16 @@ def get_qualified_name(o: Node) -> str: | |||
return '<ERROR>' | |||
|
|||
|
|||
def walk_packages(packages: List[str]): | |||
for package_name in packages: | |||
package = __import__(package_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really not happy that this imports the target package name. At the very least you should honor the --no-import
flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good point! I don't believe importing is strictly necessary here, since at this point I'm simply trying to walk the packages. I'll look into re-implementing this function without __import__
@@ -664,6 +687,8 @@ def usage() -> None: | |||
|
|||
Options: | |||
--py2 run in Python 2 mode (default: Python 3 mode) | |||
--recursive traverse listed modules to generate inner package modules as well | |||
--lenient ignore exceptions when trying to generate stubs for modules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should have a different name, maybe --ignore-errors
.
f9d04f4
to
0cf77a6
Compare
I renamed the lenient mode to After looking at |
OK. Typically we just use o's.walk(), see e.g. main.py or build.py (I
forget which).
…--Guido (mobile)
|
Thanks! If you want to work more on this just open a new PR. I'm looking to seeing more contributions from you. |
This is something I personally use for stub generation: whenever stubgen'ing a packages, you'll often want to generate modules inside of it.
If you pass in
--recursive
, then you'll generate stubs for provided modules and its included modules if its a package.Also included is
--lenient
. This will ignore exceptions (just printing a warning) when some module gens fail. This will let you stubgen for larger modules, even if they include some issues. I was having trouble using--recursive
without this.