Skip to content

Commit 89a2a8e

Browse files
committed
improve decorator typing
1 parent 4c5afee commit 89a2a8e

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ python = "^3.8"
2020
click = ">=8.0.1"
2121
numpy = "^1.24.2"
2222
pyperclip = "^1.8.2"
23+
typing-extensions = "^4.5.0"
2324

2425
[tool.poetry.group.test.dependencies]
2526
pytest = "^6.2.4"
@@ -79,6 +80,12 @@ show_column_numbers = true
7980
show_error_codes = true
8081
show_error_context = true
8182

83+
[[tool.mypy.overrides]]
84+
module = [
85+
"pyperclip.*",
86+
]
87+
ignore_missing_imports = true
88+
8289
[tool.ruff]
8390
ignore = [
8491
'B019',

src/arraytex/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
"""Utils module."""
22

33
from functools import wraps
4-
from typing import Any
54
from typing import Callable
65
from typing import TypeVar
7-
from typing import cast
86

97
import pyperclip
8+
from typing_extensions import ParamSpec
109

1110

12-
F = TypeVar("F", bound=Callable[..., str])
11+
P = ParamSpec("P")
12+
T = TypeVar("T")
1313

1414

15-
def use_clipboard(func: F) -> F:
15+
def use_clipboard(func: Callable[P, T]) -> Callable[P, str]:
1616
"""Augument decorated functions argument to copy the output to the clipboard."""
1717

1818
@wraps(func)
19-
def wrapper_func(*args: Any, **kwargs: Any) -> str:
19+
def wrapper_func(*args: P.args, **kwargs: P.kwargs) -> str:
2020
"""Wrapped function."""
2121
out = func(*args, **kwargs)
2222

2323
if kwargs.get("to_clp"):
2424
pyperclip.copy(out)
2525
print("ArrayTeX: copied to clipboard")
2626

27-
return out
27+
return str(out)
2828

29-
return cast(F, wrapper_func)
29+
return wrapper_func

0 commit comments

Comments
 (0)