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.
- {preparse-1.1.7 → preparse-1.1.8}/PKG-INFO +1 -1
- {preparse-1.1.7 → preparse-1.1.8}/docs/v1.1.rst +62 -68
- {preparse-1.1.7 → preparse-1.1.8}/pyproject.toml +1 -1
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/__init__.py +15 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/core/Click.py +28 -10
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/core/Optdict.py +15 -18
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/core/PreParser.py +16 -16
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_optdict.py +10 -0
- preparse-1.1.8/src/preparse/typing/Parser.py +5 -0
- preparse-1.1.8/src/preparse/typing/SupportsKeysAndGetitem.py +9 -0
- preparse-1.1.8/src/preparse/warnings/__init__.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/PKG-INFO +1 -1
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/SOURCES.txt +3 -0
- {preparse-1.1.7 → preparse-1.1.8}/LICENSE.txt +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/MANIFEST.in +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/README.rst +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/docs/v1.0.rst +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/setup.cfg +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Bundle.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Item.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Long.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Option.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Positional.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/Special.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_items/__init__.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/__init__.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/deparsing.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/digesting.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/parsing.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_processing/pulling.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_tests/__init__.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/_tests/expit.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/core/__init__.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/enums/BaseEnum.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/enums/Nargs.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/enums/Tuning.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/enums/__init__.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/py.typed +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/__init__.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/data.toml +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/expit.toml +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_data_toml.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_enums.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_expit_toml.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/tests/test_preparser.py +0 -0
- {preparse-1.1.7/src/preparse/warnings → preparse-1.1.8/src/preparse/typing}/__init__.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseAmbiguousOptionWarning.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseDualWarning.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseInvalidOptionWarning.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseLongonlyWarning.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseRequiredArgumentWarning.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseUnallowedArgumentWarning.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse/warnings/PreparseWarning.py +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/dependency_links.txt +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/requires.txt +0 -0
- {preparse-1.1.7 → preparse-1.1.8}/src/preparse.egg-info/top_level.txt +0 -0
|
@@ -68,11 +68,47 @@ how ``preparse`` can be used to modify ``click``.
|
|
|
68
68
|
Features
|
|
69
69
|
--------
|
|
70
70
|
|
|
71
|
-
|
|
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
|
-
``
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
289
|
-
|
|
282
|
+
``preparse.tests``
|
|
283
|
+
~~~~~~~~~~~~~~~~~~
|
|
290
284
|
|
|
291
285
|
``preparse.tests.test() -> unittest.TextTestResult``
|
|
292
286
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
@@ -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
|
|
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:
|
|
23
|
-
ctx:
|
|
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
|
-
|
|
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,
|
|
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:
|
|
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:
|
|
64
|
+
def _call_method(self: Self, target: MethodType) -> MethodType:
|
|
47
65
|
func: Callable[..., Any]
|
|
48
66
|
func = self(target.__func__)
|
|
49
|
-
return
|
|
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(
|
|
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
|
-
|
|
42
|
+
__init__ = datahold.HoldDict[Hashable, object].__init__
|
|
40
43
|
|
|
41
|
-
@
|
|
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(
|
|
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:
|
|
33
|
-
allowsshort:
|
|
34
|
-
bundling:
|
|
35
|
-
expandsabbr:
|
|
36
|
-
expectsabbr:
|
|
37
|
-
expectsposix:
|
|
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:
|
|
41
|
-
special:
|
|
42
|
-
warn: Callable = str,
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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,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
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|