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

Be more paranoid with attribute access on modules #603

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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