Skip to content

Commit ecb3506

Browse files
update dostrings
1 parent 56cee1d commit ecb3506

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

src/python_project_template_AS/calculator.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,21 @@
1717

1818

1919
class Calculator:
20-
"""Thin calculator wrapper around an OperationRegistry.
21-
22-
Methods:
23-
register(op, replace=False): Register an Operation.
24-
apply(op_name, *args): Apply a registered operation.
25-
compose(ops, left_to_right=True): Compose unary operations.
26-
chain(sequence, initial): Apply a mixed sequence DSL-style.
27-
"""
20+
"""Calculator using an OperationRegistry."""
2821

2922
def __init__(self, registry: Optional[OperationRegistry] = None):
23+
"""Create a Calculator with an optional registry."""
3024
if registry is None:
3125
self.registry = OperationRegistry()
3226
else:
3327
self.registry = registry
3428

3529
def register(self, op: Operation, *, replace: bool = False) -> None:
36-
30+
"""Register an operation, optionally replacing existing."""
3731
self.registry.register(op, replace=replace)
3832

3933
def apply(self, op_name: str, *args: Any) -> Any:
40-
34+
"""Apply a named operation with arguments."""
4135
op = self.registry.get(op_name)
4236
try:
4337
return op(*args)
@@ -49,7 +43,7 @@ def apply(self, op_name: str, *args: Any) -> Any:
4943
def compose(
5044
self, ops: Iterable[str], *, left_to_right: bool = True
5145
) -> Callable[[Any], Any]:
52-
46+
"""Compose unary operations into a single callable."""
5347
op_list: List[Operation] = [self.registry.get(name) for name in ops]
5448
for op in op_list:
5549
if op.arity != 1:
@@ -74,7 +68,7 @@ def composed(x):
7468
return composed
7569

7670
def chain(self, sequence: Iterable[Union[str, int]], initial: Any) -> Any:
77-
71+
"""Apply a sequence of operations and values starting from initial."""
7872
seq = list(sequence)
7973
cur = initial
8074
i = 0

src/python_project_template_AS/exceptions.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77

88

99
class CalculatorError(Exception):
10-
"""Base class for calculator-related errors.
11-
12-
Use this as the top-level exception when handling errors coming from the
13-
package.
14-
"""
10+
"""Base exception for calculator errors."""
1511

1612

1713
class OperationError(CalculatorError):
18-
"""Raised when an operation fails (wrong arity, invalid input, etc.)."""
14+
"""Raised for operation failures (e.g., wrong arity, invalid input)."""
1915

2016

2117
class RegistryError(CalculatorError):
22-
"""Raised for registry problems (duplicate name, not found)."""
18+
"""Raised for registry errors (duplicate or missing name)."""

src/python_project_template_AS/operations.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,27 @@
1313

1414
@dataclass
1515
class Operation:
16-
"""Container for a named callable with an expected arity.
16+
"""Named callable with arity check.
1717
1818
Attributes:
19-
name: operation name used for registry lookups.
20-
func: callable implementing the operation.
21-
arity: number of positional arguments expected by the operation.
19+
name (str): Operation name.
20+
func (Callable): Operation function.
21+
arity (int): Expected argument count.
2222
"""
2323

2424
name: str
2525
func: Callable[..., Any]
2626
arity: int = 1
2727

2828
def __call__(self, *args):
29+
"""Call operation, checking argument count.
30+
31+
Args:
32+
*args: Arguments for the operation.
33+
34+
Raises:
35+
OperationError: If argument count is wrong.
36+
"""
2937
if len(args) != self.arity:
3038
raise OperationError(
3139
f"Operation '{self.name}' expects {self.arity} arguments, got {len(args)}"

src/python_project_template_AS/utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@
88

99

1010
def is_number(x: Any) -> bool:
11-
"""Return True if ``x`` is an int or float.
12-
13-
Useful in examples and tests to guard numeric operations.
14-
"""
15-
11+
"""Return True if x is int or float."""
1612
return isinstance(x, (int, float))

0 commit comments

Comments
 (0)