python-argtools 0.0.2__py3-none-any.whl → 0.0.3__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 CHANGED
@@ -6,23 +6,25 @@ 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, 2)
9
+ __version__ = (0, 0, 3)
10
10
  __all__ = ["argcount", "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
15
  from inspect import getfullargspec
16
- from typing import cast, Any
16
+ from types import MethodType, MethodWrapperType
17
+ from typing import Any
17
18
 
18
19
 
19
20
  def argcount(func: Callable, /) -> int:
20
21
  if isinstance(func, partial):
21
22
  return max(0, argcount(func.func) - len(func.args))
23
+ is_method = isinstance(func, (MethodType, MethodWrapperType))
22
24
  try:
23
- return func.__code__.co_argcount
25
+ return func.__code__.co_argcount - is_method
24
26
  except AttributeError:
25
- return len(getfullargspec(func).args)
27
+ return len(getfullargspec(func).args) - is_method
26
28
 
27
29
 
28
30
  class Args:
@@ -53,6 +55,25 @@ class Args:
53
55
  return self.args == other.args and self.kwargs == other.kwargs
54
56
  return False
55
57
 
58
+ def __getitem__(self, idx: int | slice | str | tuple[int | slice | str, ...], /):
59
+ cls = type(self)
60
+ pget = self.args.__getitem__
61
+ if isinstance(idx, (int, slice)):
62
+ return cls(pget(idx))
63
+ kget = self.kwargs.__getitem__
64
+ if isinstance(idx, str):
65
+ return cls(idx=kget(idx))
66
+ else:
67
+ pargs: list = []
68
+ kargs: dict = {}
69
+ add_parg = pargs.append
70
+ for idx_ in idx:
71
+ if isinstance(idx_, (int, slice)):
72
+ add_parg(pget(idx_))
73
+ else:
74
+ kargs[idx_] = kget(idx_)
75
+ return cls(*pargs, **kargs)
76
+
56
77
  def __iter__(self, /):
57
78
  return iter((self.args, self.kwargs))
58
79
 
@@ -281,19 +302,19 @@ class Call[**Params, R](partial):
281
302
  **kwds: Params.kwargs,
282
303
  ):
283
304
  if hasattr(func, "func"):
284
- args = cast(Params.args, getattr(func, "args", ()) + args)
305
+ args = getattr(func, "args", ()) + args # type: ignore
285
306
  kwargs: None | dict = None
286
307
  try:
287
308
  kwargs = getattr(func, "kwargs")
288
309
  except AttributeError:
289
310
  kwargs = getattr(func, "keywords", None)
290
311
  if kwargs:
291
- kwds = cast(Params.kwargs, {**kwargs, **kwds})
312
+ kwds = {**kwargs, **kwds} # type: ignore
292
313
  func = func.func
293
314
  return update_wrapper(super().__new__(cls, func, *args, **kwds), func)
294
315
 
295
316
  @property
296
- def kwargs(self, /) -> Params.kwargs:
317
+ def kwargs(self, /) -> dict:
297
318
  return self.keywords
298
319
 
299
320
  def __call__(self, /) -> R:
@@ -1,9 +1,9 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: python-argtools
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Python argument tools.
5
- Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-argtools
6
5
  License: MIT
6
+ License-File: LICENSE
7
7
  Keywords: argument,tools
8
8
  Author: ChenyangGao
9
9
  Author-email: wosiwujm@gmail.com
@@ -16,11 +16,13 @@ Classifier: Programming Language :: Python
16
16
  Classifier: Programming Language :: Python :: 3
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
19
20
  Classifier: Programming Language :: Python :: 3 :: Only
20
21
  Classifier: Topic :: Software Development
21
22
  Classifier: Topic :: Software Development :: Libraries
22
23
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
- Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-argtools
24
+ Project-URL: Homepage, https://github.com/ChenyangGao/python-modules/tree/main/python-argtools
25
+ Project-URL: Repository, https://github.com/ChenyangGao/python-modules/tree/main/python-argtools
24
26
  Description-Content-Type: text/markdown
25
27
 
26
28
  # Python argument tools.
@@ -30,7 +32,7 @@ Description-Content-Type: text/markdown
30
32
  You can install from [pypi](https://pypi.org/project/python-argtools/)
31
33
 
32
34
  ```console
33
- pip install -U argtools
35
+ pip install -U python-argtools
34
36
  ```
35
37
 
36
38
  ## Usage
@@ -0,0 +1,6 @@
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,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.1
2
+ Generator: poetry-core 2.4.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 ChenyangGao <https://github.com/ChenyangGao>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,7 +0,0 @@
1
- LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
- argtools/__init__.py,sha256=VnzRDtsySC_7s0mh1jypHXclNG-bh_42xdICRmnDLaw,9498
3
- argtools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- python_argtools-0.0.2.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
5
- python_argtools-0.0.2.dist-info/METADATA,sha256=m36i3M9ThbvirkRV19D2rDu45N4Te9EmrXVPfbYRTQI,1275
6
- python_argtools-0.0.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
- python_argtools-0.0.2.dist-info/RECORD,,