commit: 85c490ee52be4667596a5830827128f763311b2d
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sat Nov 29 11:36:17 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sat Nov 29 11:39:45 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=85c490ee
chore: is_metaclass can be TypeGuard'd for IDE usage
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/klass/util.py | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/snakeoil/klass/util.py b/src/snakeoil/klass/util.py
index 3f94117..fa2876c 100644
--- a/src/snakeoil/klass/util.py
+++ b/src/snakeoil/klass/util.py
@@ -3,6 +3,7 @@ __all__ = (
"get_slot_of",
"get_slots_of",
"get_subclasses_of",
+ "is_metaclass",
"combine_classes",
"copy_class_docs",
"copy_docs",
@@ -14,7 +15,6 @@ import functools
import inspect
import types
import typing
-from typing import Any, Iterable
_known_builtins = frozenset(
v for k, v in vars(builtins).items() if not k.startswith("_")
@@ -26,7 +26,7 @@ class ClassSlotting(typing.NamedTuple):
slots: typing.Sequence[str] | None
-def get_slots_of(kls: type) -> Iterable[ClassSlotting]:
+def get_slots_of(kls: type) -> typing.Iterable[ClassSlotting]:
"""Visit a class MRO collecting all slotting
This cannot collect slotting of C objects- python builtins like object,
@@ -48,8 +48,11 @@ def get_slot_of(cls: type) -> ClassSlotting:
def get_attrs_of(
- obj: Any, weakref=False, suppressions: Iterable[str] = (),
_sentinel=object()
-) -> Iterable[tuple[str, Any]]:
+ obj: typing.Any,
+ weakref=False,
+ suppressions: typing.Iterable[str] = (),
+ _sentinel=object(),
+) -> typing.Iterable[tuple[str, typing.Any]]:
"""
yield the attributes of a given instance.
@@ -130,7 +133,7 @@ def get_subclasses_of(
yield current
-def is_metaclass(cls: type) -> bool:
+def is_metaclass(cls: type) -> typing.TypeGuard[type[type]]:
return issubclass(cls, type)