Skip to content

Commit

Permalink
Be more paranoid with attribute access on modules (#603)
Browse files Browse the repository at this point in the history
On some TensorFlow module, getattr(module, "__flle__", None) can throw a TypeError.
  • Loading branch information
JelleZijlstra authored Mar 31, 2023
1 parent 0cfe48a commit 03391ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

## Unreleased

- Fix crash when `getattr()` on a module object throws an error (#603)
- Fix handling of positional-only arguments using `/` syntax in stubs (#601)
- Fix bug where objects with a `__call__` method that takes `*args` instead
of `self` was not considered callable (#600)
Expand Down
5 changes: 4 additions & 1 deletion pyanalyze/node_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from typing_extensions import NotRequired, Protocol, TypedDict

from . import analysis_lib
from .safe import safe_getattr, safe_isinstance

Error = Dict[str, Any]

Expand Down Expand Up @@ -977,7 +978,9 @@ def _get_all_python_files(
if module is None:
continue
# ignore compiled modules
if not getattr(module, "__file__", None) or module.__file__.endswith(".so"):
if not safe_isinstance(
safe_getattr(module, "__file__", None), str
) or module.__file__.endswith(".so"):
continue
if cls._should_ignore_module(module_name):
continue
Expand Down

0 comments on commit 03391ad

Please sign in to comment.