mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-18 06:19:39 +08:00
Add comments to implicit namespaces and fix some minor things.
See #1005.
This commit is contained in:
+13
-6
@@ -159,10 +159,14 @@ def _iter_modules(paths, prefix=''):
|
|||||||
importer = pkgutil.get_importer(path)
|
importer = pkgutil.get_importer(path)
|
||||||
|
|
||||||
if not isinstance(importer, importlib.machinery.FileFinder):
|
if not isinstance(importer, importlib.machinery.FileFinder):
|
||||||
|
# We're only modifying the case for FileFinder. All the other cases
|
||||||
|
# still need to be checked (like zip-importing). Do this by just
|
||||||
|
# calling the pkgutil version.
|
||||||
for mod_info in pkgutil.iter_modules([path], prefix):
|
for mod_info in pkgutil.iter_modules([path], prefix):
|
||||||
yield mod_info
|
yield mod_info
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# START COPY OF pkutils._iter_file_finder_modules.
|
||||||
if importer.path is None or not os.path.isdir(importer.path):
|
if importer.path is None or not os.path.isdir(importer.path):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -177,12 +181,12 @@ def _iter_modules(paths, prefix=''):
|
|||||||
filenames.sort() # handle packages before same-named modules
|
filenames.sort() # handle packages before same-named modules
|
||||||
|
|
||||||
for fn in filenames:
|
for fn in filenames:
|
||||||
# Avoid traversing special directories
|
modname = inspect.getmodulename(fn)
|
||||||
if fn.startswith(('__', '.')):
|
if modname == '__init__' or modname in yielded:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
modname = inspect.getmodulename(fn)
|
# jedi addition: Avoid traversing special directories
|
||||||
if modname in yielded:
|
if fn.startswith('.') or fn == '__pycache__':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
path = os.path.join(importer.path, fn)
|
path = os.path.join(importer.path, fn)
|
||||||
@@ -190,16 +194,19 @@ def _iter_modules(paths, prefix=''):
|
|||||||
|
|
||||||
if not modname and os.path.isdir(path) and '.' not in fn:
|
if not modname and os.path.isdir(path) and '.' not in fn:
|
||||||
modname = fn
|
modname = fn
|
||||||
|
# A few jedi modifications: Don't check if there's an
|
||||||
|
# __init__.py
|
||||||
try:
|
try:
|
||||||
dircontents = os.listdir(path)
|
os.listdir(path)
|
||||||
except OSError:
|
except OSError:
|
||||||
# ignore unreadable directories like import does
|
# ignore unreadable directories like import does
|
||||||
dircontents = []
|
continue
|
||||||
ispkg = True
|
ispkg = True
|
||||||
|
|
||||||
if modname and '.' not in modname:
|
if modname and '.' not in modname:
|
||||||
yielded[modname] = 1
|
yielded[modname] = 1
|
||||||
yield importer, prefix + modname, ispkg
|
yield importer, prefix + modname, ispkg
|
||||||
|
# END COPY
|
||||||
|
|
||||||
iter_modules = _iter_modules if py_version >= 34 else pkgutil.iter_modules
|
iter_modules = _iter_modules if py_version >= 34 else pkgutil.iter_modules
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user