Skip to content

Commit 387d11c

Browse files
committed
Don't assume __spec__ or origin are defined.
Under Python 3.12, typing.io (deprecated and since removed) resolved to a class not a ModuleType. We should handle this case.
1 parent 3640987 commit 387d11c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

pgfutils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ def imported(self) -> set[Path]:
4848
paths = set()
4949

5050
for mod in sys.modules.values():
51-
if mod.__spec__ is None or mod.__spec__.origin is None:
51+
# Find the spec used to load the module and from that the origin. If not
52+
# given, skip this module.
53+
spec = getattr(mod, "__spec__", None)
54+
if spec is None:
55+
continue
56+
origin = getattr(spec, "origin", None)
57+
if origin is None:
5258
continue
5359

54-
path = Path(mod.__spec__.origin)
60+
path = Path(origin)
5561
if path.exists() and path.is_file():
5662
paths.add(path.resolve())
5763

0 commit comments

Comments
 (0)