python-argtools 0.0.3__py3-none-any.whl → 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- argtools/__init__.py +23 -3
- {python_argtools-0.0.3.dist-info → python_argtools-0.0.4.dist-info}/METADATA +1 -1
- python_argtools-0.0.4.dist-info/RECORD +6 -0
- python_argtools-0.0.3.dist-info/RECORD +0 -6
- {python_argtools-0.0.3.dist-info → python_argtools-0.0.4.dist-info}/WHEEL +0 -0
- {python_argtools-0.0.3.dist-info → python_argtools-0.0.4.dist-info}/licenses/LICENSE +0 -0
argtools/__init__.py
CHANGED
|
@@ -6,13 +6,13 @@ some arguments at one time and then use them repeatedly later.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
9
|
-
__version__ = (0, 0,
|
|
10
|
-
__all__ = ["argcount", "Args", "UpdativeArgs", "Call"]
|
|
9
|
+
__version__ = (0, 0, 4)
|
|
10
|
+
__all__ = ["argcount", "has_keyword_arg", "Args", "UpdativeArgs", "Call"]
|
|
11
11
|
|
|
12
12
|
from collections.abc import Callable
|
|
13
13
|
from copy import copy
|
|
14
14
|
from functools import partial, update_wrapper
|
|
15
|
-
from inspect import getfullargspec
|
|
15
|
+
from inspect import getfullargspec, signature, Parameter
|
|
16
16
|
from types import MethodType, MethodWrapperType
|
|
17
17
|
from typing import Any
|
|
18
18
|
|
|
@@ -27,6 +27,26 @@ def argcount(func: Callable, /) -> int:
|
|
|
27
27
|
return len(getfullargspec(func).args) - is_method
|
|
28
28
|
|
|
29
29
|
|
|
30
|
+
def has_keyword_arg(func: Callable, arg_name: str, /) -> bool:
|
|
31
|
+
try:
|
|
32
|
+
sig = signature(func)
|
|
33
|
+
except ValueError:
|
|
34
|
+
try:
|
|
35
|
+
arg_spec = getfullargspec(func)
|
|
36
|
+
return bool(arg_spec.varkw or arg_name in arg_spec.kwonlyargs)
|
|
37
|
+
except TypeError:
|
|
38
|
+
return False
|
|
39
|
+
else:
|
|
40
|
+
for name, param in sig.parameters.items():
|
|
41
|
+
match param.kind:
|
|
42
|
+
case Parameter.POSITIONAL_OR_KEYWORD | Parameter.KEYWORD_ONLY:
|
|
43
|
+
if name == arg_name:
|
|
44
|
+
return True
|
|
45
|
+
case Parameter.VAR_KEYWORD:
|
|
46
|
+
return True
|
|
47
|
+
return False
|
|
48
|
+
|
|
49
|
+
|
|
30
50
|
class Args:
|
|
31
51
|
"""Takes some positional arguments and keyword arguments,
|
|
32
52
|
and put them into an instance, which can be used repeatedly
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
argtools/__init__.py,sha256=r9bht478QNx7gxclRvgikMSepq6qcJrGlCEN_sjVJ8I,11018
|
|
2
|
+
argtools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
python_argtools-0.0.4.dist-info/METADATA,sha256=ZIW1ob5cWn_WeQ9zd2X4jcbjjGXv9HLvfemo2p00kjU,1337
|
|
4
|
+
python_argtools-0.0.4.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
|
|
5
|
+
python_argtools-0.0.4.dist-info/licenses/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
6
|
+
python_argtools-0.0.4.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
argtools/__init__.py,sha256=oArhrfmUaHGKFhWNb14tPHvSDasSAmqE6qRYVTYlaoo,10303
|
|
2
|
-
argtools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
python_argtools-0.0.3.dist-info/METADATA,sha256=LTRTe-O69PSnxOyCw4O5LZVfel2qrZ2HQPAqHF1CmQw,1337
|
|
4
|
-
python_argtools-0.0.3.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
|
|
5
|
-
python_argtools-0.0.3.dist-info/licenses/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
6
|
-
python_argtools-0.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|