From de926cc4782d53b9b28a2f887890d7711dfbc667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Tue, 18 Jun 2024 12:52:28 +0200 Subject: [PATCH] feat: Add `is_imported` property to objects/aliases --- src/griffe/mixins.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/griffe/mixins.py b/src/griffe/mixins.py index f3fe7913..4c07f771 100644 --- a/src/griffe/mixins.py +++ b/src/griffe/mixins.py @@ -329,6 +329,11 @@ def is_class_private(self) -> bool: """Whether this object/alias is class-private (starts with `__` and is a class member).""" return self.parent and self.parent.is_class and self.name.startswith("__") and not self.name.endswith("__") # type: ignore[attr-defined] + @property + def is_imported(self) -> bool: + """Whether this object/alias was imported from another module.""" + return self.parent and self.name in self.parent.imports # type: ignore[attr-defined] + @property def is_exported(self) -> bool: """Whether this object/alias is exported (listed in `__all__`).""" @@ -377,7 +382,7 @@ def is_wildcard_exposed(self) -> bool: return self.name in self.parent.exports # type: ignore[attr-defined] if self.name.startswith("_"): # type: ignore[attr-defined] return False - return self.is_alias or not self.is_module or self.name in self.parent.imports # type: ignore[attr-defined] + return self.is_alias or not self.is_module or self.is_imported # type: ignore[attr-defined] @property def is_public(self) -> bool: