Skip to content

Commit f549c5d

Browse files
committed
Remove __invert__ from all enums. Abusing operators is not a great choice
1 parent f10a6e1 commit f549c5d

2 files changed

Lines changed: 0 additions & 12 deletions

File tree

src/fieldenum/enums.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ def unwrap(self, default=_MISSING):
100100
case other:
101101
unreachable(other)
102102

103-
# experimental
104-
__invert__ = unwrap
105-
106103
def expect(self, message_or_exception: str | BaseException, /) -> T:
107104
match self, message_or_exception:
108105
case Option.Nothing, BaseException() as exception:
@@ -370,9 +367,6 @@ def unwrap(self, default=_MISSING):
370367
case other:
371368
unreachable(other)
372369

373-
# experimental
374-
__invert__ = unwrap
375-
376370
def as_option(self) -> Option[R]:
377371
match self:
378372
case Result.Ok(value):
@@ -532,9 +526,6 @@ def unwrap(self, default=_MISSING):
532526
case other:
533527
unreachable(other)
534528

535-
# experimental
536-
__invert__ = unwrap
537-
538529
def as_option(self) -> Option[R]:
539530
match self:
540531
case BoundResult.Success(value, _):

tests/test_enums.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ def test_option():
160160
option = Option.Some(123)
161161
assert option._0 == 123
162162
assert option.unwrap() == 123
163-
assert ~option == 123
164163
assert option.unwrap(456) == 123
165164
option = Option.Nothing
166165
assert option is Option.Nothing
@@ -233,7 +232,6 @@ def test_bound_result():
233232
# general features
234233
assert BoundResult.Success(2342, Exception) == BoundResult.Success(2342, Exception)
235234
assert BoundResult.Success(1234, Exception).unwrap() == 1234
236-
assert ~BoundResult.Success(1234, Exception) == 1234
237235
assert BoundResult.Success(1234, Exception).unwrap(34556) == 1234
238236
with pytest.raises(ValueError, match="error"):
239237
BoundResult.Failed(ValueError("error"), ValueError).unwrap()
@@ -344,7 +342,6 @@ def test_result():
344342
# general features
345343
assert Result.Ok(2342) == Result.Ok(2342)
346344
assert Result.Ok(1234).unwrap() == 1234
347-
assert ~Result.Ok(1234) == 1234
348345
assert Result.Ok(1234).unwrap(34556) == 1234
349346
with pytest.raises(ValueError, match="error"):
350347
Result.Err(ValueError("error")).unwrap()

0 commit comments

Comments
 (0)