Skip to content

Commit

Permalink
fix: Ignore cyclic alias errors when updating target aliases
Browse files Browse the repository at this point in the history
Issue #123: #123
  • Loading branch information
pawamoy committed Dec 23, 2022
1 parent b7c8861 commit bb62b2f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/griffe/dataclasses.py
Expand Up @@ -807,9 +807,7 @@ def __init__(
else:
self._target = target
self.target_path = target.path
if parent is not None:
with suppress(AliasResolutionError):
target.aliases[self.path] = self
self._update_target_aliases()

def __repr__(self) -> str:
return f"<Alias({self.name!r}, {self.target_path!r})>"
Expand Down Expand Up @@ -884,9 +882,7 @@ def parent(self) -> Module | Class | None:
@parent.setter
def parent(self, value: Module | Class) -> None:
self._parent = value
if self.resolved:
with suppress(AliasResolutionError, CyclicAliasError):
self._target.aliases[self.path] = self # type: ignore[union-attr] # we just checked the target is not None
self._update_target_aliases()

@cached_property
def path(self) -> str:
Expand Down Expand Up @@ -1122,6 +1118,10 @@ def resolve_target(self) -> None: # noqa: WPS231,WPS238
if self.parent is not None:
self._target.aliases[self.path] = self # type: ignore[union-attr] # we just set the target

def _update_target_aliases(self) -> None:
with suppress(AttributeError, AliasResolutionError, CyclicAliasError):
self._target.aliases[self.path] = self # type: ignore[union-attr]

@property
def resolved(self) -> bool:
"""Tell whether this alias' target is resolved.
Expand Down

0 comments on commit bb62b2f

Please sign in to comment.