preparse 1.1.7__tar.gz → 1.1.8__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.
Files changed (56) hide show
  1. {preparse-1.1.7 → preparse-1.1.8}/PKG-INFO +1 -1
  2. {preparse-1.1.7 → preparse-1.1.8}/docs/v1.1.rst +62 -68
  3. {preparse-1.1.7 → preparse-1.1.8}/pyproject.toml +1 -1
  4. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/__init__.py +15 -0
  5. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/core/Click.py +28 -10
  6. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/core/Optdict.py +15 -18
  7. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/core/PreParser.py +16 -16
  8. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_optdict.py +10 -0
  9. preparse-1.1.8/src/preparse/typing/Parser.py +5 -0
  10. preparse-1.1.8/src/preparse/typing/SupportsKeysAndGetitem.py +9 -0
  11. preparse-1.1.8/src/preparse/warnings/__init__.py +0 -0
  12. {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/PKG-INFO +1 -1
  13. {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/SOURCES.txt +3 -0
  14. {preparse-1.1.7 → preparse-1.1.8}/LICENSE.txt +0 -0
  15. {preparse-1.1.7 → preparse-1.1.8}/MANIFEST.in +0 -0
  16. {preparse-1.1.7 → preparse-1.1.8}/README.rst +0 -0
  17. {preparse-1.1.7 → preparse-1.1.8}/docs/v1.0.rst +0 -0
  18. {preparse-1.1.7 → preparse-1.1.8}/setup.cfg +0 -0
  19. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Bundle.py +0 -0
  20. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Item.py +0 -0
  21. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Long.py +0 -0
  22. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Option.py +0 -0
  23. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Positional.py +0 -0
  24. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Special.py +0 -0
  25. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/__init__.py +0 -0
  26. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/__init__.py +0 -0
  27. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/deparsing.py +0 -0
  28. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/digesting.py +0 -0
  29. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/parsing.py +0 -0
  30. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/pulling.py +0 -0
  31. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_tests/__init__.py +0 -0
  32. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_tests/expit.py +0 -0
  33. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/core/__init__.py +0 -0
  34. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/enums/BaseEnum.py +0 -0
  35. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/enums/Nargs.py +0 -0
  36. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/enums/Tuning.py +0 -0
  37. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/enums/__init__.py +0 -0
  38. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/py.typed +0 -0
  39. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/__init__.py +0 -0
  40. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/data.toml +0 -0
  41. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/expit.toml +0 -0
  42. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_data_toml.py +0 -0
  43. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_enums.py +0 -0
  44. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_expit_toml.py +0 -0
  45. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_preparser.py +0 -0
  46. {preparse-1.1.7/src/preparse/warnings → preparse-1.1.8/src/preparse/typing}/__init__.py +0 -0
  47. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseAmbiguousOptionWarning.py +0 -0
  48. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseDualWarning.py +0 -0
  49. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseInvalidOptionWarning.py +0 -0
  50. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseLongonlyWarning.py +0 -0
  51. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseRequiredArgumentWarning.py +0 -0
  52. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseUnallowedArgumentWarning.py +0 -0
  53. {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseWarning.py +0 -0
  54. {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/dependency_links.txt +0 -0
  55. {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/requires.txt +0 -0
  56. {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: preparse
3
- Version: 1.1.7
3
+ Version: 1.1.8
4
4
  Summary: This project preparses args for further parsing later on.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License-Expression: MIT
@@ -68,11 +68,47 @@ how ``preparse`` can be used to modify ``click``.
68
68
  Features
69
69
  --------
70
70
 
71
- The ``PreParser`` class
72
- ~~~~~~~~~~~~~~~~~~~~~~~
71
+ ``preparse.core``
72
+ ~~~~~~~~~~~~~~~~~
73
+
74
+ ``class preparse.core.Click.Click(parser: preparse.PreParser, cmd: object = True, ctx: object = True)``
75
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76
+
77
+ This dataclass provides decorators for embedding a ``PreParser`` object.
78
+
79
+ ``__call__(target: types.FunctionType) -> types.FunctionType`` ``__call__(target: types.MethodType) -> types.MethodType`` ``__call__(target: types.TargetParser) -> types.TargetParser``
80
+ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
81
+
82
+ This magic method implements ``self(target)``.
83
+ It works as a decorator that embeds its parser into a given target from the library ``click``.
84
+
85
+ ``cmd: object``
86
+ """""""""""""""
87
+
88
+ This ``property`` determines if the ``reflectClickCommand`` method of parser is to be called.
89
+
90
+ ``copy() -> Self``
91
+ """"""""""""""""""
73
92
 
74
- ``class preparse.PreParser(*, allowslong: Any = True, allowsshort: Any = True, bundling: Any = Tuning.MAINTAIN, expandsabbr: Any = True, expectsabbr: Any = True, expectsposix: Any = False, optdict: Any = (), prog: Any = None, reconcilesorders: Any = True, special: Any = preparse.Tuning.MAINTAIN, warn: Callable = str)``
75
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
93
+ ``ctx: object``
94
+ """""""""""""""
95
+
96
+ This ``property`` determines if the ``reflectClickContext`` method of parser is to be called.
97
+
98
+ ``parser: preparse.PreParser``
99
+ """"""""""""""""""""""""""""""
100
+
101
+ This ``property`` holds the parser to be embedded.
102
+
103
+ ``class preparse.core.Optdict.Optdict``
104
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105
+
106
+ This class is a subclass of ``datahold.HoldDict[str, preparse.Nargs]``
107
+ with strings as keys and with ``preparse.Nargs`` as values.
108
+ It is designed for ``preparse.PreParser.optdict``.
109
+
110
+ ``class preparse.core.PreParser.PreParser(*, allowslong: object = True, allowsshort: object = True, bundling: int = Tuning.MAINTAIN, expandsabbr: object = True, expectsabbr: object = True, expectsposix: object = False, optdict: Any = (), prog: object = None, reconcilesorders: object = True, special: int = preparse.Tuning.MAINTAIN, warn: Callable[[PreparseWarning], Any] = str)``
111
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76
112
 
77
113
  This ``class`` is the centerpiece of the ``preparse``.
78
114
  Its behaviour follows the principles of ``getopt`` from ``C``.
@@ -92,8 +128,8 @@ This boolean ``property`` determines whether short options are allowed.
92
128
 
93
129
  This ``property`` determines the approach to bundling of short option.
94
130
 
95
- ``click(cmd: Any = True, ctx: Any = True) -> preparse.Click``
96
- """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
131
+ ``click(cmd: object = True, ctx: object = True) -> preparse.Click``
132
+ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
97
133
 
98
134
  This method returns a decorator that infuses the current instance into ``parse_args``.
99
135
 
@@ -181,56 +217,14 @@ No keyword arguments are given.
181
217
  Its return value is discarded.
182
218
  Therefore, ``str`` is used to discard the warnings.
183
219
 
184
- The Click class
185
- ~~~~~~~~~~~~~~~
186
-
187
- ``class preparse.Click(parser: preparse.PreParser, cmd: Any = True, ctx: Any = True)``
188
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189
-
190
- This dataclass provides decorators for embedding a ``PreParser`` object.
191
-
192
- ``__call__(target: Any) -> Any``
193
- """"""""""""""""""""""""""""""""
194
-
195
- This magic method implements ``self(target)``.
196
- It works as a decorator that embeds its parser into a given target from the library ``click``.
197
-
198
- ``cmd: Any``
199
- """"""""""""
200
-
201
- This ``property`` determines if the ``reflectClickCommand`` method of parser is to be called.
202
-
203
- ``copy() -> Self``
204
- """"""""""""""""""
205
-
206
- ``ctx: Any``
207
- """"""""""""
208
-
209
- This ``property`` determines if the ``reflectClickContext`` method of parser is to be called.
210
-
211
- ``parser: preparse.PreParser``
212
- """"""""""""""""""""""""""""""
213
-
214
- This ``property`` holds the parser to be embedded.
215
-
216
- The Optdict class
217
- ~~~~~~~~~~~~~~~~~
218
-
219
- ``class preparse.Optdict``
220
- ^^^^^^^^^^^^^^^^^^^^^^^^^^
221
-
222
- This class is a subclass of ``datahold.HoldDict[str, preparse.Nargs]``
223
- with strings as keys and with ``preparse.Nargs`` as values.
224
- It is designed for ``preparse.PreParser.optdict``.
225
-
226
- The Enums
227
- ~~~~~~~~~
220
+ ``preparse.enums``
221
+ ~~~~~~~~~~~~~~~~~~
228
222
 
229
223
  These classes are subclasses of ``enum.IntEnum``.
230
224
  Any value different from ``0`` (meaning no) and ``1`` (meaning yes) is interpreted as ``2`` (meaning intermediate).
231
225
 
232
- ``class preparse.Tuning``
233
- ^^^^^^^^^^^^^^^^^^^^^^^^^
226
+ ``class preparse.enums.Tuning.Tuning``
227
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
234
228
 
235
229
  +--------------+-------+-----------------------------------------------------------------------------+
236
230
  | Name | Value | Explanation |
@@ -242,8 +236,8 @@ Any value different from ``0`` (meaning no) and ``1`` (meaning yes) is interpret
242
236
  | ``MAINTAIN`` | ``2`` | The PreParser does not make any unforced changes to the aspect in question. |
243
237
  +--------------+-------+-----------------------------------------------------------------------------+
244
238
 
245
- ``class preparse.Nargs``
246
- ^^^^^^^^^^^^^^^^^^^^^^^^
239
+ ``class preparse.enums.Nargs.Nargs``
240
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
247
241
 
248
242
  +-------------------+-------+----------------------------------------------+
249
243
  | Name | Value | Explanation |
@@ -255,38 +249,38 @@ Any value different from ``0`` (meaning no) and ``1`` (meaning yes) is interpret
255
249
  | OPTIONAL_ARGUMENT | ``2`` | The option may take an argument. |
256
250
  +-------------------+-------+----------------------------------------------+
257
251
 
258
- The Warnings
259
- ~~~~~~~~~~~~
252
+ ``preparse.warnings``
253
+ ~~~~~~~~~~~~~~~~~~~~~
260
254
 
261
255
  These classes are subclasses of ``Warning`` that are specifically designed to communicate issues with parsing.
262
256
 
263
- ``class preparse.PreparseWarning``
264
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
257
+ ``class preparse.warnings.PreparseWarning.PreparseWarning``
258
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
265
259
 
266
260
  This abstract base ``class`` is the base for all other warning types.
267
261
 
268
- ``class preparse.PreparseAmbiguousOptionWarning(prog: Any, option: Any, possibilities: Any)``
269
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
262
+ ``class preparse.warnings.PreparseAmbiguousOptionWarning.PreparseAmbiguousOptionWarning(prog: Any, option: Any, possibilities: Any)``
263
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
270
264
 
271
265
  This ``class`` warns about ambiguous options. This can only happen for long options.
272
266
 
273
- ``class preparse.PreparseInvalidOptionWarning(prog: Any, option: Any, islong: Any)``
274
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
267
+ ``class preparse.warnings.PreparseInvalidOptionWarning.PreparseInvalidOptionWarning(prog: Any, option: Any, islong: Any)``
268
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
275
269
 
276
270
  This ``class`` warns about invalid options.
277
271
 
278
- ``class preparse.PreparseRequiredArgumentWarning(prog: Any, option: Any, islong: Any)``
279
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
272
+ ``class preparse.warnings.PreparseRequiredArgumentWarning.PreparseRequiredArgumentWarning(prog: Any, option: Any, islong: Any)``
273
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
280
274
 
281
275
  This ``class`` warns about missing required arguments.
282
276
 
283
- ``class preparse.PreparseUnallowedArgumentWarning(prog: Any, option: Any)``
284
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
277
+ ``class preparse.warnings.PreparseUnallowedArgumentWarning.PreparseUnallowedArgumentWarning(prog: Any, option: Any)``
278
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
285
279
 
286
280
  This ``class`` warns about unallowed arguments. This can only happen for long options.
287
281
 
288
- The Tests
289
- ~~~~~~~~~
282
+ ``preparse.tests``
283
+ ~~~~~~~~~~~~~~~~~~
290
284
 
291
285
  ``preparse.tests.test() -> unittest.TextTestResult``
292
286
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ license-files = [
36
36
  name = "preparse"
37
37
  readme = "README.rst"
38
38
  requires-python = ">=3.11"
39
- version = "1.1.7"
39
+ version = "1.1.8"
40
40
 
41
41
  [project.urls]
42
42
  Download = "https://pypi.org/project/preparse/#files"
@@ -1,3 +1,5 @@
1
+ from preparse.core.Click import Click
2
+ from preparse.core.Optdict import Optdict
1
3
  from preparse.core.PreParser import PreParser
2
4
  from preparse.enums.Nargs import Nargs
3
5
  from preparse.enums.Tuning import Tuning
@@ -14,3 +16,16 @@ from preparse.warnings.PreparseUnallowedArgumentWarning import (
14
16
  PreparseUnallowedArgumentWarning,
15
17
  )
16
18
  from preparse.warnings.PreparseWarning import PreparseWarning
19
+
20
+ __all__ = [
21
+ "PreParser",
22
+ "Optdict",
23
+ "Click",
24
+ "Nargs",
25
+ "Tuning",
26
+ "PreparseAmbiguousOptionWarning",
27
+ "PreparseInvalidOptionWarning",
28
+ "PreparseRequiredArgumentWarning",
29
+ "PreparseUnallowedArgumentWarning",
30
+ "PreparseWarning",
31
+ ]
@@ -2,9 +2,9 @@ from __future__ import annotations
2
2
 
3
3
  import dataclasses
4
4
  import functools
5
- import types
6
5
  from collections.abc import Callable
7
- from typing import TYPE_CHECKING, Any, Self
6
+ from types import FunctionType, MethodType
7
+ from typing import TYPE_CHECKING, Any, Self, cast, overload
8
8
 
9
9
  import setdoc
10
10
  from copyable import Copyable
@@ -19,18 +19,36 @@ __all__ = ["Click"]
19
19
  class Click(Copyable):
20
20
 
21
21
  parser: PreParser
22
- cmd: Any = True
23
- ctx: Any = True
22
+ cmd: object = True
23
+ ctx: object = True
24
24
 
25
+ @overload
26
+ def __call__(self: Self, target: FunctionType) -> FunctionType:
27
+ "This magic method implements self(target)."
28
+ ...
29
+
30
+ @overload
31
+ def __call__(self: Self, target: MethodType) -> MethodType:
32
+ "This magic method implements self(target)."
33
+ ...
34
+
35
+ @overload
25
36
  def __call__(self: Self, target: Any) -> Any:
26
37
  "This magic method implements self(target)."
27
- if isinstance(target, types.FunctionType):
38
+ ...
39
+
40
+ def __call__(
41
+ self: Self,
42
+ target: Any,
43
+ ) -> Any:
44
+ "This magic method implements self(target)."
45
+ if isinstance(target, FunctionType):
28
46
  return self._call_function(target)
29
- if isinstance(target, types.MethodType):
47
+ if isinstance(target, MethodType):
30
48
  return self._call_method(target)
31
49
  return self._call_other(target)
32
50
 
33
- def _call_function(self: Self, target: types.FunctionType) -> Any:
51
+ def _call_function(self: Self, target: FunctionType) -> FunctionType:
34
52
  @functools.wraps(target)
35
53
  def ans(cmd: Any, ctx: Any, args: Any) -> Any:
36
54
  p: Any
@@ -41,12 +59,12 @@ class Click(Copyable):
41
59
  p.reflectClickContext(ctx)
42
60
  return target(cmd, ctx, p.parse_args(args))
43
61
 
44
- return ans
62
+ return cast(FunctionType, ans)
45
63
 
46
- def _call_method(self: Self, target: types.MethodType) -> types.MethodType:
64
+ def _call_method(self: Self, target: MethodType) -> MethodType:
47
65
  func: Callable[..., Any]
48
66
  func = self(target.__func__)
49
- return types.MethodType(func, target.__self__)
67
+ return MethodType(func, target.__self__)
50
68
 
51
69
  def _call_other(self: Self, target: Any) -> Any:
52
70
  target.parse_args = self(target.parse_args)
@@ -1,13 +1,13 @@
1
- from collections.abc import Hashable
1
+ from collections.abc import Hashable, Iterable
2
2
  from typing import Any, Optional, Self, cast
3
3
 
4
4
  import cmp3
5
5
  import datahold
6
6
  import setdoc
7
- from datarepr import datarepr
8
7
  from frozendict import frozendict
9
8
 
10
9
  from preparse.enums.Nargs import Nargs
10
+ from preparse.typing.SupportsKeysAndGetitem import SupportsKeysAndGetitem
11
11
 
12
12
  __all__ = ["Optdict"]
13
13
 
@@ -19,7 +19,10 @@ def nargs(value: Any, /) -> Nargs:
19
19
  return Nargs.OPTIONAL_ARGUMENT
20
20
 
21
21
 
22
- class Optdict(cmp3.CmpABC, datahold.HoldDict[str, Nargs]):
22
+ class Optdict(
23
+ cmp3.CmpABC,
24
+ datahold.HoldDict[str, Nargs],
25
+ ):
23
26
  __slots__ = ()
24
27
 
25
28
  _data: frozendict[str, Nargs]
@@ -36,28 +39,22 @@ class Optdict(cmp3.CmpABC, datahold.HoldDict[str, Nargs]):
36
39
  Optional[int], cmp3.cmp(self._data, other, mode="eq_strict")
37
40
  )
38
41
 
39
- __format__ = object.__format__
42
+ __init__ = datahold.HoldDict[Hashable, object].__init__
40
43
 
41
- @setdoc.basic
42
- def __init__(self: Self, data: Any = (), /) -> None:
43
- datahold.HoldDict.__init__(self, data)
44
-
45
- @setdoc.basic
46
- def __repr__(self: Self, /) -> str:
47
- return datarepr(type(self).__name__, dict(self._data))
48
-
49
- __str__ = object.__str__
50
-
51
- @property # type: ignore[override]
44
+ @property
52
45
  def data(self: Self) -> frozendict[str, Nargs]:
53
46
  return frozendict(self._data)
54
47
 
55
- @data.setter
56
- def data(self: Self, value: Any) -> None:
48
+ @data.setter # type: ignore[override]
49
+ def data(
50
+ self: Self,
51
+ value: SupportsKeysAndGetitem | Iterable[tuple[Hashable, object]],
52
+ /,
53
+ ) -> None:
57
54
  a: frozendict[Hashable, object]
58
55
  x: map[str]
59
56
  y: map[Nargs]
60
- a = frozendict(value)
57
+ a = frozendict(value) # type: ignore[arg-type]
61
58
  x = map(str, a.keys())
62
59
  y = map(nargs, a.values())
63
60
  self._data = frozendict(zip(x, y, strict=True))
@@ -29,17 +29,17 @@ class PreParser(Copyable):
29
29
  def __init__(
30
30
  self: Self,
31
31
  *,
32
- allowslong: Any = True,
33
- allowsshort: Any = True,
34
- bundling: Any = Tuning.MAINTAIN,
35
- expandsabbr: Any = True,
36
- expectsabbr: Any = True,
37
- expectsposix: Any = False,
32
+ allowslong: object = True,
33
+ allowsshort: object = True,
34
+ bundling: int = Tuning.MAINTAIN,
35
+ expandsabbr: object = True,
36
+ expectsabbr: object = True,
37
+ expectsposix: object = False,
38
38
  optdict: Any = (),
39
39
  prog: object = None,
40
- reconcilesorders: Any = True,
41
- special: Any = Tuning.MAINTAIN,
42
- warn: Callable = str, # type: ignore[type-arg]
40
+ reconcilesorders: object = True,
41
+ special: int = Tuning.MAINTAIN,
42
+ warn: Callable[[PreparseWarning], Any] = str,
43
43
  ) -> None:
44
44
  self._data: dict[str, Any]
45
45
  self._data = dict()
@@ -64,7 +64,7 @@ class PreParser(Copyable):
64
64
  return cast(bool, self._data["allowslong"])
65
65
 
66
66
  @allowslong.setter
67
- def allowslong(self: Self, value: Any) -> None:
67
+ def allowslong(self: Self, value: object) -> None:
68
68
  self._data["allowslong"] = bool(value)
69
69
 
70
70
  @property
@@ -72,7 +72,7 @@ class PreParser(Copyable):
72
72
  return cast(bool, self._data["allowsshort"])
73
73
 
74
74
  @allowsshort.setter
75
- def allowsshort(self: Self, value: Any) -> None:
75
+ def allowsshort(self: Self, value: object) -> None:
76
76
  self._data["allowsshort"] = bool(value)
77
77
 
78
78
  @property
@@ -85,7 +85,7 @@ class PreParser(Copyable):
85
85
  "This property decides how to approach the bundling of short options."
86
86
  self._data["bundling"] = Tuning(value)
87
87
 
88
- def click(self: Self, cmd: Any = True, ctx: Any = True) -> Click:
88
+ def click(self: Self, cmd: object = True, ctx: object = True) -> Click:
89
89
  "This method returns a decorator that infuses the current instance into parse_args."
90
90
  return Click(parser=self, cmd=cmd, ctx=ctx)
91
91
 
@@ -98,7 +98,7 @@ class PreParser(Copyable):
98
98
  return cast(bool, self._data["expandsabbr"])
99
99
 
100
100
  @expandsabbr.setter
101
- def expandsabbr(self: Self, value: Any, /) -> None:
101
+ def expandsabbr(self: Self, value: object, /) -> None:
102
102
  self._data["expandsabbr"] = bool(value)
103
103
 
104
104
  @property
@@ -106,7 +106,7 @@ class PreParser(Copyable):
106
106
  return cast(bool, self._data["expectsabbr"])
107
107
 
108
108
  @expectsabbr.setter
109
- def expectsabbr(self: Self, value: Any) -> None:
109
+ def expectsabbr(self: Self, value: object) -> None:
110
110
  self._data["expectsabbr"] = bool(value)
111
111
 
112
112
  @property
@@ -114,7 +114,7 @@ class PreParser(Copyable):
114
114
  return cast(bool, self._data["expectsposix"])
115
115
 
116
116
  @expectsposix.setter
117
- def expectsposix(self: Self, value: Any) -> None:
117
+ def expectsposix(self: Self, value: object) -> None:
118
118
  value_: Any
119
119
  if value == "infer":
120
120
  value_ = os.environ.get("POSIXLY_CORRECT")
@@ -162,7 +162,7 @@ class PreParser(Copyable):
162
162
  return cast(bool, self._data["reconcilesorders"])
163
163
 
164
164
  @reconcilesorders.setter
165
- def reconcilesorders(self: Self, value: Any, /) -> None:
165
+ def reconcilesorders(self: Self, value: object, /) -> None:
166
166
  self._data["reconcilesorders"] = bool(value)
167
167
 
168
168
  def reflectClickCommand(self: Self, cmd: cl.Command) -> None:
@@ -2,6 +2,7 @@ import unittest
2
2
  from typing import Self
3
3
 
4
4
  from preparse.core.Optdict import Optdict
5
+ from preparse.enums.Nargs import Nargs
5
6
 
6
7
  __all__ = ["TestPreparse"]
7
8
 
@@ -15,6 +16,15 @@ class TestPreparse(unittest.TestCase):
15
16
  dublicate = original.copy()
16
17
  self.assertEqual(original, dublicate)
17
18
 
19
+ def test_optdict_repr(self: Self) -> None:
20
+ data: dict[str, Nargs]
21
+ original: Optdict
22
+ data = {"--foo": Nargs.NO_ARGUMENT, "-bar": Nargs.REQUIRED_ARGUMENT}
23
+ original = Optdict(data)
24
+ self.assertEqual(repr(original), f"Optdict({data})")
25
+ self.assertEqual(repr(original), str(original))
26
+ self.assertEqual(repr(original), format(original))
27
+
18
28
 
19
29
  if __name__ == "__main__":
20
30
  unittest.main()
@@ -0,0 +1,5 @@
1
+ from typing import Any, Callable, Protocol
2
+
3
+
4
+ class Parser(Protocol):
5
+ parse_args: Callable[..., Any]
@@ -0,0 +1,9 @@
1
+ from collections.abc import Hashable
2
+ from typing import Protocol, Self
3
+
4
+ __all__ = ["SupportsKeysAndGetitem"]
5
+
6
+
7
+ class SupportsKeysAndGetitem(Protocol):
8
+ def __getitem__(self: Self, key: Hashable, /) -> object: ...
9
+ def keys(self: Self) -> tuple[Hashable, ...]: ...
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: preparse
3
- Version: 1.1.7
3
+ Version: 1.1.8
4
4
  Summary: This project preparses args for further parsing later on.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License-Expression: MIT
@@ -42,6 +42,9 @@ src/preparse/tests/test_enums.py
42
42
  src/preparse/tests/test_expit_toml.py
43
43
  src/preparse/tests/test_optdict.py
44
44
  src/preparse/tests/test_preparser.py
45
+ src/preparse/typing/Parser.py
46
+ src/preparse/typing/SupportsKeysAndGetitem.py
47
+ src/preparse/typing/__init__.py
45
48
  src/preparse/warnings/PreparseAmbiguousOptionWarning.py
46
49
  src/preparse/warnings/PreparseDualWarning.py
47
50
  src/preparse/warnings/PreparseInvalidOptionWarning.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes