Skip to content

Commit b69f1d1

Browse files
committed
Extract 'is_local' filter to avoid computing relative_to(base(module)) twice (or forgetting to do so).
1 parent f38ceb6 commit b69f1d1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

discovery.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,23 @@ def base(module):
158158
return '.'.join((best_name(),) + module.parent.parts)
159159

160160

161+
def is_local(import_):
162+
return import_.name.startswith(best_name())
163+
164+
161165
def inferred_deps():
162166
"""
163167
Infer deps from module imports.
164168
"""
165-
names = [
166-
(imp.relative_to(base(module)), module)
169+
imps = (
170+
types.SimpleNamespace(name=imp.relative_to(base(module)), module=module)
167171
for module in filter(is_python, source_files())
168172
for imp in imports.get_module_imports(module)
169173
if not imp.standard()
170-
and not imp.relative_to(base(module)).startswith(best_name())
171-
]
172-
for name, module in names:
174+
)
175+
for imp in itertools.filterfalse(is_local, imps):
173176
# TODO(#30): Handle resolution errors gracefully
174-
yield pypi.distribution_for(name) + extra_for(module)
177+
yield pypi.distribution_for(imp.name) + extra_for(imp.module)
175178

176179

177180
def combined_deps():

0 commit comments

Comments
 (0)