Skip to content

Commit 0411505

Browse files
author
Mehdi Drissi
committed
Avoid recursion in tensorflow import fallback.
1 parent 7a7a582 commit 0411505

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

astroid/brain/brain_tensorflow.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88

99
def _tensorflow_fail_hook(modname: str):
1010
parts = modname.split(".", 1)
11+
fallbacks = ("python", "_api.v2")
1112
if parts[0] == "tensorflow":
12-
parts[0] = "tensorflow.python"
13-
return MANAGER.ast_from_module_name(".".join(parts))
13+
for fallback in fallbacks:
14+
if parts[1].startswith(fallbacks):
15+
continue
16+
try:
17+
return MANAGER.ast_from_module_name(f"tensorflow.{fallback}.{parts[1]}")
18+
except AstroidBuildingError:
19+
continue
1420
raise AstroidBuildingError(modname=modname)
1521

1622

0 commit comments

Comments
 (0)