From e1f3ed9ad3b046bf137de22f855bb392a76ca116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Tue, 10 Sep 2024 17:01:39 +0200 Subject: [PATCH] fix: Don't crash when trying to merge stubs into a compiled module that has no file path Issue-323: https://github.com/mkdocstrings/griffe/issues/323 --- src/_griffe/mixins.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/_griffe/mixins.py b/src/_griffe/mixins.py index 8957920a..1eddecab 100644 --- a/src/_griffe/mixins.py +++ b/src/_griffe/mixins.py @@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, Any, Sequence, TypeVar from _griffe.enumerations import Kind -from _griffe.exceptions import AliasResolutionError, CyclicAliasError +from _griffe.exceptions import AliasResolutionError, BuiltinModuleError, CyclicAliasError from _griffe.merger import merge_stubs if TYPE_CHECKING: @@ -204,7 +204,9 @@ def set_member(self, key: str | Sequence[str], value: Object | Alias) -> None: # try to merge them as one regular and one stubs module # (implicit support for .pyi modules). if member.is_module and not (member.is_namespace_package or member.is_namespace_subpackage): - with suppress(AliasResolutionError, CyclicAliasError): + # Accessing attributes of the value or member can trigger alias errors. + # Accessing file paths can trigger a builtin module error. + with suppress(AliasResolutionError, CyclicAliasError, BuiltinModuleError): if value.is_module and value.filepath != member.filepath: with suppress(ValueError): value = merge_stubs(member, value) # type: ignore[arg-type]