Skip to content

Commit b9e226e

Browse files
authored
Extra type check on utils.is_std Fixes #148 (#149)
1 parent e1ce37b commit b9e226e

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

unimport/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ def is_std(package: str) -> bool:
5050
if package in C.BUILTIN_MODULE_NAMES:
5151
return True
5252
spec = get_spec(package)
53-
return bool(spec) and any(
54-
(
55-
spec.origin.startswith(C.STDLIB_PATH),
56-
spec.origin in ["built-in", "frozen"],
57-
spec.origin.endswith(".so"),
53+
if spec and isinstance(spec.origin, str):
54+
return any(
55+
(
56+
spec.origin.startswith(C.STDLIB_PATH),
57+
spec.origin in ["built-in", "frozen"],
58+
spec.origin.endswith(".so"),
59+
)
5860
)
59-
)
61+
else:
62+
return False
6063

6164

6265
@functools.lru_cache(maxsize=None)

0 commit comments

Comments
 (0)