Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add brain to fix tensorflow import errors. #2174

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add brain to fix tensorflow import errors.
Mehdi Drissi committed May 9, 2023

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
commit b1fd84134ed96e0abb82fa56c010bd4ad1d5ddb2
14 changes: 14 additions & 0 deletions astroid/brain/brain_tensorflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Astroid hooks for understanding tensorflow's imports."""
from astroid import MANAGER
from astroid.exceptions import AstroidBuildingError


def _tensorflow_fail_hook(modname: str):
parts = modname.split(".", 1)
if parts[0] == "tensorflow":
parts[0] = "tensorflow.python"
return MANAGER.ast_from_module_name(".".join(parts))
raise AstroidBuildingError(modname=modname)


MANAGER.register_failed_import_hook(_tensorflow_fail_hook)