Skip to content

Commit

Permalink
fix: Don't crash when trying to merge stubs into a compiled module th…
Browse files Browse the repository at this point in the history
…at has no file path

Issue-323: #323
  • Loading branch information
pawamoy committed Sep 10, 2024
1 parent 676cfb4 commit e1f3ed9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/_griffe/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit e1f3ed9

Please # to comment.