Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 782fcfb

Browse files
author
mpheath
committedOct 25, 2020
Minor improvement to _import_modules() building of the modules list.
1 parent ee29e55 commit 782fcfb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed
 

‎gen_python_3_api.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,31 +1668,34 @@ def _import_modules(modules):
16681668
else:
16691669
import_stats['pass'] += 1
16701670

1671-
# Get list of module names and module objects from copy of sys.modules.
1672-
sys_modules = sys.modules.copy()
1671+
# Get list of module names and module objects from sys.modules.
16731672
modules = []
1673+
prefixes = tuple(self.settings['exclude_modules_startswith'])
1674+
1675+
for module in sorted(sys.modules):
1676+
if module in ('__main__', '__mp_main__'):
1677+
continue
16741678

1675-
for module in sys_modules:
16761679
if module in self.settings['exclude_modules_fullname']:
16771680
continue
16781681

1679-
if module.startswith(tuple(self.settings['exclude_modules_startswith'])):
1682+
if module.startswith(prefixes):
16801683
continue
16811684

16821685
if self.settings['exclude_modules_startswith_underscore']:
1683-
passed = True
1686+
underscored = False
16841687

16851688
for item in module.split('.'):
16861689
if item.startswith('_'):
1687-
passed = False
1690+
underscored = True
16881691
break
16891692

1690-
if not passed:
1693+
if underscored:
16911694
continue
16921695

1693-
modules.append([module, sys_modules[module]])
1696+
modules.append([module, sys.modules[module]])
16941697

1695-
return sorted(modules), import_stats
1698+
return modules, import_stats
16961699

16971700

16981701
if modules is None:

0 commit comments

Comments
 (0)
Please sign in to comment.