Skip to content

Commit

Permalink
improve decorator typing
Browse files Browse the repository at this point in the history
  • Loading branch information
dbatten5 committed Mar 17, 2023
1 parent 4c5afee commit 89a2a8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ python = "^3.8"
click = ">=8.0.1"
numpy = "^1.24.2"
pyperclip = "^1.8.2"
typing-extensions = "^4.5.0"

[tool.poetry.group.test.dependencies]
pytest = "^6.2.4"
Expand Down Expand Up @@ -79,6 +80,12 @@ show_column_numbers = true
show_error_codes = true
show_error_context = true

[[tool.mypy.overrides]]
module = [
"pyperclip.*",
]
ignore_missing_imports = true

[tool.ruff]
ignore = [
'B019',
Expand Down
14 changes: 7 additions & 7 deletions src/arraytex/utils.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
"""Utils module."""

from functools import wraps
from typing import Any
from typing import Callable
from typing import TypeVar
from typing import cast

import pyperclip
from typing_extensions import ParamSpec


F = TypeVar("F", bound=Callable[..., str])
P = ParamSpec("P")
T = TypeVar("T")


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

@wraps(func)
def wrapper_func(*args: Any, **kwargs: Any) -> str:
def wrapper_func(*args: P.args, **kwargs: P.kwargs) -> str:
"""Wrapped function."""
out = func(*args, **kwargs)

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

return out
return str(out)

return cast(F, wrapper_func)
return wrapper_func

0 comments on commit 89a2a8e

Please sign in to comment.