-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Added support for reading .pyi files. #4824
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,6 +156,17 @@ def import_object(modname, objpath, objtype='', attrgetter=safe_getattr, warning | |
|
||
try: | ||
module = import_module(modname, warningiserror=warningiserror) | ||
import os | ||
if hasattr(module, '__file__') and os.path.isfile('{}i'.format(module.__file__)): | ||
try: | ||
from importlib._bootstrap import spec_from_loader | ||
from importlib._bootstrap_external import SourceFileLoader | ||
from importlib._bootstrap import module_from_spec | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: these functions are provided by |
||
spec = spec_from_loader(modname, SourceFileLoader(modname, '{}i'.format(module.__file__))) | ||
module = module_from_spec(spec) | ||
spec.loader.exec_module(module) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this overrides whole of modules by .pyi's. Is this right? |
||
except BaseException as e: | ||
raise e | ||
logger.debug('[autodoc] => %r', module) | ||
obj = module | ||
parent = None | ||
|
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 adding new code to here is a bit ugly. How about moving this to helper function?