Skip to content

Commit

Permalink
Build the real signature for the main functions
Browse files Browse the repository at this point in the history
and remove useless import
  • Loading branch information
Gouvernathor committed May 20, 2024
1 parent 5a4d86d commit cbf7323
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/parliamentarch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from inspect import signature
from io import TextIOBase

from .geometry import get_seats_centers
from .svg import SeatData, dispatch_seats, get_grouped_svg
from ._util import filter_kwargs, write_from_get

__all__ = ("get_svg_from_attribution", "write_svg_from_attribution", "SeatData")

_GET_SEATS_CENTERS_PARAM_NAMES = {k for k, p in signature(get_seats_centers).parameters.items() if p.kind==p.KEYWORD_ONLY}
_WRITE_GROUPED_SVG_PARAM_NAMES = {k for k, p in signature(get_grouped_svg).parameters.items() if p.kind==p.KEYWORD_ONLY}
_GET_SEATS_CENTERS_PARAM_NAMES = {k: p for k, p in signature(get_seats_centers).parameters.items() if p.kind==p.KEYWORD_ONLY}
_WRITE_GROUPED_SVG_PARAM_NAMES = {k: p for k, p in signature(get_grouped_svg).parameters.items() if p.kind==p.KEYWORD_ONLY}

def get_svg_from_attribution(attrib: dict[SeatData, int], **kwargs) -> str:
nseats = sum(attrib.values())
Expand All @@ -21,4 +20,13 @@ def get_svg_from_attribution(attrib: dict[SeatData, int], **kwargs) -> str:
seat_centers_by_group = dispatch_seats(attrib, sorted(results, key=results.__getitem__, reverse=True))
return get_grouped_svg(seat_centers_by_group, results.seat_actual_radius, **write_grouped_svg_kwargs)

_sig = signature(get_svg_from_attribution)
_attrib_param = _sig.parameters["attrib"]
get_svg_from_attribution.__signature__ = _sig.replace(parameters=(
_attrib_param,
*_GET_SEATS_CENTERS_PARAM_NAMES.values(),
*_WRITE_GROUPED_SVG_PARAM_NAMES.values()
))
del _sig, _attrib_param

write_svg_from_attribution = write_from_get(get_svg_from_attribution)

0 comments on commit cbf7323

Please sign in to comment.