Skip to content

Commit

Permalink
Merge pull request #7 from daizutabi/6-revert-allow-keyword-args-for-…
Browse files Browse the repository at this point in the history
…template-mathods

Revert: allow keyword args for template mathods
  • Loading branch information
daizutabi authored Oct 1, 2024
2 parents a1615d5 + 64efc20 commit 7595f11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
22 changes: 3 additions & 19 deletions src/textconf/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from __future__ import annotations

import inspect
from inspect import Parameter, Signature
from inspect import Signature
from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Callable, Iterable, Iterator
from collections.abc import Callable, Iterator
from typing import Any, TypeGuard


Expand Down Expand Up @@ -114,20 +114,4 @@ def is_template_method(obj: object) -> TypeGuard[Callable[[Any], Any]]:
if signature.return_annotation in [None, "None", Signature.empty]:
return False

return is_template_params(signature.parameters.values())


def is_template_params(params: Iterable[Parameter]) -> bool:
"""Check if the parameters are valid template parameters.
A valid template parameter is a positional or keyword parameter that has
no default value and is not a variable positional or keyword parameter.
"""
params = list(params)

for p in params:
if p.kind in [Parameter.VAR_POSITIONAL, Parameter.VAR_KEYWORD]:
return False

return len([p for p in params if p.default == Parameter.empty]) == 1
return len(signature.parameters) == 1
5 changes: 2 additions & 3 deletions tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,13 @@ def test_is_template_method_two_var():
def test_is_template_method_pkwarg():
from textconf.template import is_template_method

assert is_template_method(Class.c_pkwarg)
assert not is_template_method(Class.c_pkwarg)


def test_iter_template_methods():
from textconf.template import iter_template_methods

it = iter_template_methods(Class)
assert next(it) == ("c_int", Class.c_int)
assert next(it) == ("c_pkwarg", Class.c_pkwarg)
assert next(it) == ("c_str", Class.c_str)
assert len(list(iter_template_methods(Class))) == 3
assert len(list(iter_template_methods(Class))) == 2

0 comments on commit 7595f11

Please sign in to comment.