Skip to content

Commit ae7c7e7

Browse files
committed
refactor: Rename has_private_name and has_special_name to is_private and is_special
1 parent 1ebfa63 commit ae7c7e7

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/griffe/mixins.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,32 @@ def attributes(self) -> dict[str, Attribute]:
296296

297297
@property
298298
def has_private_name(self) -> bool:
299-
"""Whether this object/alias has a private name."""
299+
"""Deprecated. Use [`is_private`][griffe.Object.is_private] instead."""
300+
warnings.warn(
301+
"The `has_private_name` property is deprecated. Use `is_private` instead.",
302+
DeprecationWarning,
303+
stacklevel=2,
304+
)
300305
return self.name.startswith("_") # type: ignore[attr-defined]
301306

302307
@property
303308
def has_special_name(self) -> bool:
304-
"""Whether this object/alias has a special name."""
309+
"""Deprecated. Use [`is_special`][griffe.Object.is_special] instead."""
310+
warnings.warn(
311+
"The `has_special_name` property is deprecated. Use `is_special` instead.",
312+
DeprecationWarning,
313+
stacklevel=2,
314+
)
315+
return self.name.startswith("__") and self.name.endswith("__") # type: ignore[attr-defined]
316+
317+
@property
318+
def is_private(self) -> bool:
319+
"""Whether this object/alias is private (starts with `_`) but not special."""
320+
return self.name.startswith("_") and not self.is_special # type: ignore[attr-defined]
321+
322+
@property
323+
def is_special(self) -> bool:
324+
"""Whether this object/alias is special ("dunder" attribute/method, starts and end with `__`)."""
305325
return self.name.startswith("__") and self.name.endswith("__") # type: ignore[attr-defined]
306326

307327
@property
@@ -350,7 +370,7 @@ def is_wildcard_exposed(self) -> bool:
350370
return False
351371
if self.parent.exports is not None: # type: ignore[attr-defined]
352372
return self.name in self.parent.exports # type: ignore[attr-defined]
353-
if self.has_private_name:
373+
if self.name.startswith("_"): # type: ignore[attr-defined]
354374
return False
355375
return self.is_alias or not self.is_module or self.name in self.parent.imports # type: ignore[attr-defined]
356376

@@ -383,7 +403,7 @@ def is_public(self) -> bool:
383403
# Special objects are always considered public.
384404
# Even if we don't access them directly, they are used through different *public* means
385405
# like instantiating classes (`__init__`), using operators (`__eq__`), etc..
386-
if self.has_private_name and not self.has_special_name:
406+
if self.is_private:
387407
return _False # type: ignore[return-value]
388408

389409
# TODO: In a future version, we will support two conventions regarding imports:

0 commit comments

Comments
 (0)