From 37ae0a2f37c7e446c890d9e1204edddfb3591dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Wed, 30 Nov 2022 19:21:16 +0100 Subject: [PATCH] fix: Fix comparing names with strings Issue #114: https://github.com/mkdocstrings/griffe/issues/114 --- src/griffe/expressions.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/griffe/expressions.py b/src/griffe/expressions.py index b9490e3a..af7baa5b 100644 --- a/src/griffe/expressions.py +++ b/src/griffe/expressions.py @@ -29,8 +29,12 @@ def __init__(self, source: str, full: str | Callable) -> None: self._full = "" self._resolver = full - def __eq__(self, other: Name | Expression) -> bool: # type: ignore[override] - return self.full == other.full # noqa: WPS437 + def __eq__(self, other: Any) -> bool: + if isinstance(other, str): + return self.full == other or self.brief == other + if isinstance(other, (Name, Expression)): + return self.full == other.full # noqa: WPS437 + raise NotImplementedError(f"uncomparable types: {type(self)} and {type(other)}") def __repr__(self) -> str: return f"Name(source={self.source!r}, full={self.full!r})"