Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_module_names(mod, directory, *, allow_dynamic=True, _found=()):
"""
Get the names defined in the module 'mod'
'directory' should be the directory where the file with the import is.
This is only used for static import determination.
If allow_dynamic=True, then external module names are found by importing
the module directly.
"""
try:
names = get_names_from_dir(mod, directory, allow_dynamic=allow_dynamic, _found=_found)
except ExternalModuleError:
if allow_dynamic:
names = get_names_dynamically(mod)
else:
raise NotImplementedError("Static determination of external module imports is not supported.")
return names