Skip to content

Commit

Permalink
move fix_signature to utils
Browse files Browse the repository at this point in the history
it will be reused now.
  • Loading branch information
rsalmei committed Feb 27, 2021
1 parent 370d4ef commit 1175dc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 1 addition & 12 deletions alive_progress/animations/spinner_compiler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import operator
import random
import time
from functools import update_wrapper
from inspect import signature
from itertools import chain, count, islice, repeat
from types import SimpleNamespace
from typing import Callable

from about_time import about_time

from .utils import fix_signature
from ..utils.cells import fix_cells, is_wide, join_cells, strip_marks, to_cells
from ..utils.colors import BLUE, BLUE_BOLD, CYAN, DIM, GREEN, ORANGE, ORANGE_BOLD, RED, YELLOW_BOLD
from ..utils.terminal import hide_cursor, show_cursor
Expand Down Expand Up @@ -66,16 +65,6 @@ def inner_schedule(*args, **kwargs):
return inner_controller


def fix_signature(func: Callable, source: Callable, skip_n_params: int):
"""Override signature to hide first n parameters."""
doc = () if func.__doc__ else ('__doc__',)
update_wrapper(func, source, assigned=('__module__', '__name__', '__qualname__') + doc)
sig = signature(func)
sig = sig.replace(parameters=tuple(sig.parameters.values())[skip_n_params:])
func.__signature__ = sig
return func


"""
The commands here are made available in the compiler controller, thus in all spinners.
Expand Down
14 changes: 13 additions & 1 deletion alive_progress/animations/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import math
from functools import reduce, wraps
from functools import reduce, update_wrapper, wraps
from inspect import signature
from itertools import accumulate, chain, repeat
from typing import Callable

from ..utils.cells import combine_cells, fix_cells, mark_graphemes, split_graphemes

Expand Down Expand Up @@ -108,3 +110,13 @@ def spread_weighted(actual_length, naturals):
lengths = tuple(map(lambda a, b: a - b, lengths, [0] + lengths))
assert sum(lengths) == actual_length
return lengths


def fix_signature(func: Callable, source: Callable, skip_n_params: int):
"""Override signature to hide first n parameters."""
doc = () if func.__doc__ else ('__doc__',)
update_wrapper(func, source, assigned=('__module__', '__name__', '__qualname__') + doc)
sig = signature(func)
sig = sig.replace(parameters=tuple(sig.parameters.values())[skip_n_params:])
func.__signature__ = sig
return func

0 comments on commit 1175dc9

Please sign in to comment.