Skip to content

Commit 373541c

Browse files
committed
refactor: change raised() method to raises()
1 parent 9c88687 commit 373541c

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

ResultContainer/ResultContainer.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
Error Handling:
2626
- The `ResultErr` class captures error messages, codes, and optional traceback information.
27-
- Errors only raise an exception when requested (`expect` or `raised` methods).
27+
- Errors only raise an exception when requested (`expect` or `raises` methods).
2828
2929
Constructors:
3030
Result(value, success=True, error_msg="", error_code=1, error_code_group=1):
@@ -185,7 +185,7 @@
185185
"Err_msg",
186186
"Err_code",
187187
"Err_traceback",
188-
"raised",
188+
"raises",
189189
"expect",
190190
"expect_Err",
191191
"unwrap",
@@ -427,7 +427,7 @@ class ResultErr(Exception):
427427
error (bool): Returns true if in error status (ie, size > 0).
428428
429429
Methods:
430-
raised(note=""):
430+
raises(note=""):
431431
Raise a ResultErr exception if error messages exist
432432
and optionally add the note to the end of exception.
433433
@@ -469,23 +469,23 @@ class ResultErr(Exception):
469469
>>> err = ResultErr() # empty error
470470
>>> print(err.error)
471471
False
472-
>>> err.raised() # Nothing happens
472+
>>> err.raises() # Nothing happens
473473
>>>
474474
>>> err.append("bad input")
475-
>>> err.raised() # program terminates
475+
>>> err.raises() # program terminates
476476
ResultErr: bad input
477477
478478
>>> err = ResultErr("bad input") # Initialized with an error
479479
>>> print(err.error)
480480
True
481-
>>> err.raised() # program terminals
481+
>>> err.raises() # program terminals
482482
ResultErr: bad input
483483
484484
>>> err = ResultErr("bad input 1") # Initialized with an error
485485
>>> err.append("bad input 2") # Second error message
486486
>>> print(err.error)
487487
True
488-
>>> err.raised() # program terminates
488+
>>> err.raises() # program terminates
489489
ResultErr:
490490
bad input 1
491491
bad input 2
@@ -618,7 +618,7 @@ def error_code_description(self, description=None, error_code_group=None):
618618
return self.__class__._error_codes[g]
619619
return self.__class__._error_codes[g][description]
620620

621-
def raised(self, note=""):
621+
def raises(self, note=""):
622622
"""
623623
Raise a ResultErr exception if there are error messages.
624624
@@ -631,7 +631,7 @@ def raised(self, note=""):
631631
raise self
632632

633633
def expect(self, error_msg=""):
634-
self.raised(error_msg)
634+
self.raises(error_msg)
635635
return ResultErr()
636636

637637
def unwrap(self, *args, **kwargs):
@@ -858,7 +858,7 @@ class Result:
858858
If Ok variant, then raise ResultErr(ok_msg);
859859
If Err variant, then returns error in Err(error), which is type ResultErr.
860860
861-
raised(error_msg="", exception=None):
861+
raises(error_msg="", exception=None):
862862
If Ok variant, then returns Ok(value);
863863
If Err variant, then raise Err and optionally include `from exception`.
864864
Useful for check during chained operations
@@ -1075,7 +1075,7 @@ def expect_Err(self, ok_msg="", error_code=5): # 5 -> ResultErr.error_code("Exp
10751075
err.append(ok_msg, add_traceback=False)
10761076
raise ResultErr(err)
10771077

1078-
def raised(self, error_msg="", exception: Exception = None):
1078+
def raises(self, error_msg="", exception: Exception = None):
10791079
self._empty_error()
10801080
if not self._success:
10811081
if error_msg != "":
@@ -1371,14 +1371,14 @@ def method(*args, **kwargs):
13711371
res = attr(*args, **kwargs)
13721372
return Result(res) if res is not None else None
13731373
except Exception as e:
1374-
return Result.Err(f"VAR.{name}() raised {e}", self.error_code("Method"), self._g)
1374+
return Result.Err(f"VAR.{name}() raises {e}", self.error_code("Method"), self._g)
13751375

13761376
return method
13771377
if isinstance(attr, Result):
13781378
return attr
13791379
return Result(attr)
13801380
except AttributeError:
1381-
self.add_Err_msg(f"VAR.{name} raised an AttributeError", self.error_code("Attribute"))
1381+
self.add_Err_msg(f"VAR.{name} raises an AttributeError", self.error_code("Attribute"))
13821382
return self
13831383

13841384
def __iter__(self):

tests/test_advanced.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_result_err_initialization():
2424
result.expect()
2525

2626
with pytest.raises(ResultErr):
27-
result.raised()
27+
result.raises()
2828

2929

3030
# Edge Case Initialization
@@ -33,7 +33,7 @@ def test_result_ok_with_none():
3333
assert result.is_Ok is True
3434
assert result.unwrap() is None
3535
assert result.expect() is None
36-
assert result.raised() == Ok(None)
36+
assert result.raises() == Ok(None)
3737

3838

3939
def test_result_err_with_empty_string():
@@ -44,7 +44,7 @@ def test_result_err_with_empty_string():
4444
result.expect()
4545

4646
with pytest.raises(ResultErr):
47-
result.raised()
47+
result.raises()
4848

4949

5050
# Iter Tests
@@ -111,12 +111,12 @@ def test_result_apply():
111111
error_result.expect()
112112

113113
with pytest.raises(ResultErr):
114-
error_result.raised()
114+
error_result.raises()
115115

116116
with pytest.raises(ResultErr):
117117
# apply returns Err for bad function
118118
mapped_result = Ok(0).apply(lambda x: 10 / x)
119-
mapped_result.raised()
119+
mapped_result.raises()
120120

121121

122122
def test_result_map():
@@ -132,7 +132,7 @@ def test_result_map():
132132
error_result.expect()
133133

134134
with pytest.raises(ResultErr):
135-
error_result.raised()
135+
error_result.raises()
136136

137137
with pytest.raises(ZeroDivisionError):
138138
# map raises exception for bad function
@@ -205,7 +205,7 @@ def test_result_apply_chain():
205205
.apply(lambda x: Result.Ok(x * 0)) # Ok(40)
206206
.apply(lambda x: Result.Ok(10 / x)) # Raises ZeroDiv Error
207207
.apply(lambda x: Result.Ok(x + 1)) # Appends to error message
208-
.raised() # Raises Exception if in Err state
208+
.raises() # Raises Exception if in Err state
209209
)
210210

211211

@@ -255,7 +255,7 @@ def test_division_by_zero():
255255
zero_result = Ok(0)
256256
with pytest.raises(ResultErr):
257257
ans = result / zero_result
258-
ans.raised()
258+
ans.raises()
259259

260260

261261
def test_modulo():
@@ -299,7 +299,7 @@ def test_error_message_integrity():
299299
result = Err(error_message)
300300
assert result.Err_msg == ["Critical Error"]
301301
with pytest.raises(ResultErr):
302-
result.raised()
302+
result.raises()
303303

304304

305305
def test_error_chaining_integrity():

tests/test_basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def test_resulterr_append():
8181

8282

8383
# Test for ResultErr raised
84-
def test_resulterr_raised():
85-
err = ResultErr("This is a raised error", code=500)
84+
def test_resulterr_raises():
85+
err = ResultErr("This is a raises error", code=500)
8686
with pytest.raises(ResultErr):
87-
err.raised()
87+
err.raises()
8888

8989

9090
# Test for expect() with Ok result

0 commit comments

Comments
 (0)