python-argtools 0.0.2__tar.gz → 0.0.3__tar.gz

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.
@@ -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
@@ -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,12 +1,12 @@
1
1
  [tool.poetry]
2
2
  name = "python-argtools"
3
- version = "0.0.2"
3
+ version = "0.0.3"
4
4
  description = "Python argument tools."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
7
7
  readme = "readme.md"
8
- homepage = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-argtools"
9
- repository = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-argtools"
8
+ homepage = "https://github.com/ChenyangGao/python-modules/tree/main/python-argtools"
9
+ repository = "https://github.com/ChenyangGao/python-modules/tree/main/python-argtools"
10
10
  keywords = ["argument", "tools"]
11
11
  classifiers = [
12
12
  "License :: OSI Approved :: MIT License",
@@ -5,7 +5,7 @@
5
5
  You can install from [pypi](https://pypi.org/project/python-argtools/)
6
6
 
7
7
  ```console
8
- pip install -U argtools
8
+ pip install -U python-argtools
9
9
  ```
10
10
 
11
11
  ## Usage
File without changes