-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dice: eliminate near-duplicate regex matching of dice expressions
Matching on the dice expression pattern only once is more efficient, and it simplifies the code. Passing a dice expression `re.Match` to `_roll_dice()` eliminates any need for the pesky `InvalidDiceExpressionError` case that was impossible to cover using only the example decorator (and the `if result is None` check was a recent addition to help the type-checker, rather than an actual runtime requirement). I only wish that there was an equivalent to `re.findall()` that returns a *list* of `re.Match` objects instead of an iterator, but the list comprehension required to use `re.finditer()` isn't *that* bad.
- Loading branch information
Showing
1 changed file
with
17 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters