Skip to content

Commit e9ba4d6

Browse files
committed
refactor!: rename class_method to classmethod
1 parent eec0e23 commit e9ba4d6

3 files changed

Lines changed: 8 additions & 44 deletions

File tree

objinspect/__init__.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ def inspect(
1414
public: bool = True,
1515
inherited: bool = True,
1616
static_methods: bool = True,
17-
class_method: bool = False,
17+
classmethod: bool = False,
1818
protected: bool = False,
1919
private: bool = False,
20-
**legacy_options: object,
2120
) -> Function | Class | Method:
2221
"""
2322
Inspects an object and returns a structured representation of its attributes and methods.
@@ -33,10 +32,9 @@ def inspect(
3332
public (bool, optional): Whether to include public attributes and methods.
3433
inherited (bool, optional): Whether to include inherited attributes and methods.
3534
static_methods (bool, optional): Whether to include static methods.
36-
class_method (bool, optional): Whether to include class methods.
35+
classmethod (bool, optional): Whether to include class methods.
3736
protected (bool, optional): Whether to include protected attributes and methods (prefixed with _).
3837
private (bool, optional): Whether to include private attributes and methods (prefixed with __).
39-
**legacy_options: Backward-compatible keyword options (supports `classmethod`).
4038
4139
Returns:
4240
An object representing the structure of the inspected object.
@@ -70,22 +68,13 @@ def inspect(
7068
return Function(obj)
7169
return Method(obj, cls)
7270

73-
legacy_classmethod = legacy_options.pop("classmethod", None)
74-
if legacy_classmethod is not None:
75-
if not isinstance(legacy_classmethod, bool):
76-
raise TypeError("`classmethod` must be a bool")
77-
class_method = legacy_classmethod
78-
if legacy_options:
79-
unexpected_keys = ", ".join(sorted(legacy_options))
80-
raise TypeError(f"Unexpected keyword argument(s): {unexpected_keys}")
81-
8271
return Class(
8372
obj,
8473
init=init,
8574
public=public,
8675
inherited=inherited,
8776
static_methods=static_methods,
88-
class_method=class_method,
77+
classmethod=classmethod,
8978
protected=protected,
9079
private=private,
9180
)

objinspect/_class.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Class:
2828
public (bool, optional): Include public methods.
2929
inherited (bool, optional): Include inherited methods.
3030
static_methods (bool, optional): Include static methods.
31-
class_method (bool, optional): Include class methods.
31+
classmethod (bool, optional): Include class methods.
3232
protected (bool, optional): Include protected methods.
3333
private (bool, optional): Include private methods.
3434
@@ -54,19 +54,9 @@ def __init__(
5454
static_methods: bool = True,
5555
protected: bool = False,
5656
private: bool = False,
57-
class_method: bool = True,
57+
classmethod: bool = True,
5858
skip_self: bool = True,
59-
**legacy_options: object,
6059
) -> None:
61-
legacy_classmethod = legacy_options.pop("classmethod", None)
62-
if legacy_classmethod is not None:
63-
if not isinstance(legacy_classmethod, bool):
64-
raise TypeError("`classmethod` must be a bool")
65-
class_method = legacy_classmethod
66-
if legacy_options:
67-
unexpected_keys = ", ".join(sorted(legacy_options))
68-
raise TypeError(f"Unexpected keyword argument(s): {unexpected_keys}")
69-
7060
self.cls = cls
7161
self.skip_self = skip_self
7262
self.receieved_instance = not inspect.isclass(cls)
@@ -88,7 +78,7 @@ def __init__(
8878
"static_methods": static_methods,
8979
"protected": protected,
9080
"private": private,
91-
"class_method": class_method,
81+
"classmethod": classmethod,
9282
}
9383
self._methods = self._find_methods()
9484
self.has_init = "__init__" in self._methods

objinspect/method.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55
from objinspect.function import Function
66

77

8-
def _resolve_class_method_option(class_method: bool, legacy_options: dict[str, object]) -> bool:
9-
legacy_classmethod = legacy_options.pop("classmethod", None)
10-
if legacy_classmethod is not None:
11-
if not isinstance(legacy_classmethod, bool):
12-
raise TypeError("`classmethod` must be a bool")
13-
class_method = legacy_classmethod
14-
if legacy_options:
15-
unexpected_keys = ", ".join(sorted(legacy_options))
16-
raise TypeError(f"Unexpected keyword argument(s): {unexpected_keys}")
17-
return class_method
18-
19-
208
class Method(Function):
219
"""
2210
The Method class represents a method of a class.
@@ -106,11 +94,8 @@ def __init__(
10694
static_methods: bool = True,
10795
protected: bool = False,
10896
private: bool = False,
109-
class_method: bool = False,
110-
**legacy_options: object,
97+
classmethod: bool = False,
11198
) -> None:
112-
class_method = _resolve_class_method_option(class_method, dict(legacy_options))
113-
11499
self.checks: list[Callable[[Method], bool]] = []
115100
filter_checks: tuple[tuple[bool, Callable[[Method], bool]], ...] = (
116101
(not init, lambda method: method.name == "__init__"),
@@ -119,7 +104,7 @@ def __init__(
119104
(not private, lambda method: method.is_private),
120105
(not protected, lambda method: method.is_protected),
121106
(not public, lambda method: method.is_public),
122-
(not class_method, lambda method: method.is_classmethod),
107+
(not classmethod, lambda method: method.is_classmethod),
123108
)
124109
for enabled, check in filter_checks:
125110
if enabled:

0 commit comments

Comments
 (0)