Skip to content

Commit

Permalink
draft of parameter conversion
Browse files Browse the repository at this point in the history
this isn't really exactly the right place: we only want to do this in the
IPC version of things, not the lazy.* version, since the lazy.* version
should just have users passing the right things, so this will result in a
bunch of extra useless work. but it's an example of parameter hoisting.

Signed-off-by: Tycho Andersen <[email protected]>
  • Loading branch information
tych0 committed Mar 16, 2024
1 parent 04354d5 commit 3fb2cd3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion libqtile/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from __future__ import annotations

import abc
import collections
import inspect
import sys
import traceback
Expand All @@ -42,6 +43,10 @@
ItemT = Optional[tuple[bool, list[str | int]]]


def tail(n, iterable):
return iter(collections.dequeue(iterable, maxlen=n))


def expose_command(name: Callable | str | list[str] | None = None) -> Callable:
"""
Decorator to expose methods to the command interface.
Expand Down Expand Up @@ -74,7 +79,22 @@ def wrapper(func: Callable):
func._mapping.append(name) # type:ignore
else:
logger.error("Unexpected value received in command decorator: %s", name)
return func

def type_converter(*args, **kwargs):
converted_args = []
converted_kwargs = dict()

params = inspect.signature(func).parameters

for arg, param in zip(args, params):
converted_args.append(param.annotation(arg))

for k, v in kwargs:
converted_kwargs[k] = params[k].annotation(v)

func(*converted_args, **converted_kwargs)

return type_converter

# If the decorator is added with no parentheses then we should treat it
# as if it had been i.e. expose the decorated method
Expand Down

0 comments on commit 3fb2cd3

Please sign in to comment.