Skip to content

Commit

Permalink
use poseur for older python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
rbroderi committed May 8, 2022
1 parent c3ee46d commit 7d6f3e7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ isolated_build = true
[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39
Expand Down
22 changes: 21 additions & 1 deletion verbex/verbex.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ def __str__(self) -> str:
VerbexEscapedCharClassOrSpecial: TypeAlias = Union["Verbex", EscapedCharClassOrSpecial]


def _poseur_decorator(*poseur: Any) -> Any:
"""Positional-only arguments runtime checker."""
import functools

def caller(func: Callable[P, R]) -> Callable[P, R]: # type: ignore
@functools.wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
poseur_args = set(poseur).intersection(kwargs) # type: ignore
if poseur_args:
raise TypeError(
"%s() got some positional-only arguments passed as keyword"
" arguments: %r" % (func.__name__, ", ".join(poseur_args)),
)
return func(*args, **kwargs) # type: ignore

return wrapper

return caller


class Verbex:
"""
VerbalExpressions class.
Expand Down Expand Up @@ -248,9 +268,9 @@ def _capture_group_without_name(

@re_escape
@beartype
@_poseur_decorator("self")
def capture_group(
self,
/,
name_or_text: Union[Optional[str], VerbexEscapedCharClassOrSpecial] = None,
text: Optional[VerbexEscapedCharClassOrSpecial] = None,
) -> Verbex:
Expand Down

0 comments on commit 7d6f3e7

Please sign in to comment.