Skip to content

Commit c35c246

Browse files
committed
dice: remove dead code for addition argument to DicePouch
The equation evaluator has been taking care of this since 2013, when the `addition` argument was hard-coded to `0` in a dice-rolling rewrite. See commit 5a8ecf4 for some of the history. A decade later, in 2023, we have no use for this argument. The code to handle it is unreachable, which affects the plugin's coverage score. Best solution is to just remove the dead code.
1 parent 543b423 commit c35c246

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

sopel/modules/dice.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717

1818

1919
class DicePouch:
20-
def __init__(self, num_of_die, type_of_die, addition):
20+
def __init__(self, num_of_die, type_of_die):
2121
"""Initialize dice pouch and roll the dice.
2222
2323
Args:
2424
num_of_die: number of dice in the pouch.
2525
type_of_die: how many faces the dice have.
26-
addition: how much is added to the result of the dice.
2726
"""
2827
self.num = num_of_die
2928
self.type = type_of_die
30-
self.addition = addition
3129

3230
self.dice = {}
3331
self.dropped = {}
@@ -70,7 +68,7 @@ def drop_lowest(self, n):
7068
del self.dice[i]
7169

7270
def get_simple_string(self):
73-
"""Return the values of the dice like (2+2+2[+1+1])+1."""
71+
"""Return the values of the dice like (2+2+2[+1+1])."""
7472
dice = self.dice.items()
7573
faces = ("+".join([str(face)] * times) for face, times in dice)
7674
dice_str = "+".join(faces)
@@ -81,14 +79,10 @@ def get_simple_string(self):
8179
dfaces = ("+".join([str(face)] * times) for face, times in dropped)
8280
dropped_str = "[+%s]" % ("+".join(dfaces),)
8381

84-
plus_str = ""
85-
if self.addition:
86-
plus_str = "{:+d}".format(self.addition)
87-
88-
return "(%s%s)%s" % (dice_str, dropped_str, plus_str)
82+
return "(%s%s)" % (dice_str, dropped_str)
8983

9084
def get_compressed_string(self):
91-
"""Return the values of the dice like (3x2[+2x1])+1."""
85+
"""Return the values of the dice like (3x2[+2x1])."""
9286
dice = self.dice.items()
9387
faces = ("%dx%d" % (times, face) for face, times in dice)
9488
dice_str = "+".join(faces)
@@ -99,15 +93,11 @@ def get_compressed_string(self):
9993
dfaces = ("%dx%d" % (times, face) for face, times in dropped)
10094
dropped_str = "[+%s]" % ("+".join(dfaces),)
10195

102-
plus_str = ""
103-
if self.addition:
104-
plus_str = "{:+d}".format(self.addition)
105-
106-
return "(%s%s)%s" % (dice_str, dropped_str, plus_str)
96+
return "(%s%s)" % (dice_str, dropped_str)
10797

10898
def get_sum(self):
109-
"""Get the sum of non-dropped dice and the addition."""
110-
result = self.addition
99+
"""Get the sum of non-dropped dice."""
100+
result = 0
111101
for face, times in self.dice.items():
112102
result += face * times
113103
return result
@@ -155,7 +145,7 @@ def _roll_dice(bot, dice_expression):
155145
bot.reply('I only have 1000 dice. =(')
156146
return None # Signal there was a problem
157147

158-
dice = DicePouch(dice_num, dice_type, 0)
148+
dice = DicePouch(dice_num, dice_type)
159149

160150
if result.group('drop_lowest'):
161151
drop = int(result.group('drop_lowest'))

0 commit comments

Comments
 (0)