Skip to content

Commit

Permalink
Emit warning when too many seats are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Gouvernathor committed May 4, 2024
1 parent b731e19 commit a9ad909
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/parliamentarch/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from functools import cached_property
from io import TextIOBase
import re
import warnings

from ._util import Color, UnPicklable, get_from_write

Expand Down Expand Up @@ -51,11 +52,15 @@ def dispatch_seats[S](
The length of the iterable should be the sum of the values in the dict.
Typically the groups are ordered from the left to the right,
and the seats are ordered from the left to the right.
If too few seats are passed, an exception is raised.
If too many seats are passed, a warning is emitted.
"""
its = iter(seats)
rv = {}
for group, nseats in group_seats.items():
rv[group] = [next(its) for _ in range(nseats)]
if tuple(its):
warnings.warn("Too many seats were passed to dispatch_seats.")
return rv


Expand Down

0 comments on commit a9ad909

Please sign in to comment.