preparse 1.1.7__tar.gz → 1.1.9__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 (55) hide show
  1. {preparse-1.1.7 → preparse-1.1.9}/PKG-INFO +1 -1
  2. {preparse-1.1.7 → preparse-1.1.9}/docs/v1.1.rst +103 -89
  3. {preparse-1.1.7 → preparse-1.1.9}/pyproject.toml +1 -1
  4. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/__init__.py +15 -0
  5. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_items/Bundle.py +2 -2
  6. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_items/Long.py +1 -1
  7. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_processing/digesting.py +2 -2
  8. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/core/Click.py +28 -10
  9. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/core/Optdict.py +15 -18
  10. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/core/PreParser.py +21 -18
  11. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/tests/test_optdict.py +10 -0
  12. preparse-1.1.9/src/preparse/typing/SupportsKeysAndGetitem.py +9 -0
  13. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/warnings/PreparseAmbiguousOptionWarning.py +3 -3
  14. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/warnings/PreparseDualWarning.py +6 -2
  15. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/warnings/PreparseUnallowedArgumentWarning.py +1 -1
  16. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/warnings/PreparseWarning.py +2 -2
  17. preparse-1.1.9/src/preparse/warnings/__init__.py +0 -0
  18. {preparse-1.1.7 → preparse-1.1.9}/src/preparse.egg-info/PKG-INFO +1 -1
  19. {preparse-1.1.7 → preparse-1.1.9}/src/preparse.egg-info/SOURCES.txt +2 -0
  20. {preparse-1.1.7 → preparse-1.1.9}/LICENSE.txt +0 -0
  21. {preparse-1.1.7 → preparse-1.1.9}/MANIFEST.in +0 -0
  22. {preparse-1.1.7 → preparse-1.1.9}/README.rst +0 -0
  23. {preparse-1.1.7 → preparse-1.1.9}/docs/v1.0.rst +0 -0
  24. {preparse-1.1.7 → preparse-1.1.9}/setup.cfg +0 -0
  25. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_items/Item.py +0 -0
  26. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_items/Option.py +0 -0
  27. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_items/Positional.py +0 -0
  28. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_items/Special.py +0 -0
  29. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_items/__init__.py +0 -0
  30. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_processing/__init__.py +0 -0
  31. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_processing/deparsing.py +0 -0
  32. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_processing/parsing.py +0 -0
  33. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_processing/pulling.py +0 -0
  34. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_tests/__init__.py +0 -0
  35. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/_tests/expit.py +0 -0
  36. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/core/__init__.py +0 -0
  37. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/enums/BaseEnum.py +0 -0
  38. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/enums/Nargs.py +0 -0
  39. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/enums/Tuning.py +0 -0
  40. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/enums/__init__.py +0 -0
  41. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/py.typed +0 -0
  42. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/tests/__init__.py +0 -0
  43. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/tests/data.toml +0 -0
  44. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/tests/expit.toml +0 -0
  45. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/tests/test_data_toml.py +0 -0
  46. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/tests/test_enums.py +0 -0
  47. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/tests/test_expit_toml.py +0 -0
  48. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/tests/test_preparser.py +0 -0
  49. {preparse-1.1.7/src/preparse/warnings → preparse-1.1.9/src/preparse/typing}/__init__.py +0 -0
  50. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/warnings/PreparseInvalidOptionWarning.py +0 -0
  51. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/warnings/PreparseLongonlyWarning.py +0 -0
  52. {preparse-1.1.7 → preparse-1.1.9}/src/preparse/warnings/PreparseRequiredArgumentWarning.py +0 -0
  53. {preparse-1.1.7 → preparse-1.1.9}/src/preparse.egg-info/dependency_links.txt +0 -0
  54. {preparse-1.1.7 → preparse-1.1.9}/src/preparse.egg-info/requires.txt +0 -0
  55. {preparse-1.1.7 → preparse-1.1.9}/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.9
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,49 @@ 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: typing.Any) -> typing.Any``
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
+ """"""""""""""""""
92
+
93
+ This method returns a shallow copy of the current decorator.
94
+
95
+ ``ctx: object``
96
+ """""""""""""""
97
+
98
+ This ``property`` determines if the ``reflectClickContext`` method of parser is to be called.
99
+
100
+ ``parser: preparse.core.PreParser.PreParser``
101
+ """""""""""""""""""""""""""""""""""""""""""""
102
+
103
+ This ``property`` holds the parser to be embedded.
73
104
 
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
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105
+ ``class preparse.core.Optdict.Optdict(data: preparse.typing.SupportsKeysAndGetitem.SupportsKeysAndGetitem | Iterable[tuple[Hashable, object]] = (), /)``
106
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107
+
108
+ This class is a subclass of ``datahold.HoldDict[str, preparse.Nargs]``
109
+ with strings as keys and with ``preparse.Nargs`` as values.
110
+ It is designed for ``preparse.PreParser.optdict``.
111
+
112
+ ``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: preparse.typing.SupportsKeysAndGetitem.SupportsKeysAndGetitem | Iterable[tuple[Hashable, object]] = (), prog: object = None, reconcilesorders: object = True, special: int = preparse.Tuning.MAINTAIN, warn: Callable[[PreparseWarning], Any] = str)``
113
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76
114
 
77
115
  This ``class`` is the centerpiece of the ``preparse``.
78
116
  Its behaviour follows the principles of ``getopt`` from ``C``.
@@ -90,10 +128,10 @@ This boolean ``property`` determines whether short options are allowed.
90
128
  ``bundling: preparse.Tuning``
91
129
  """""""""""""""""""""""""""""
92
130
 
93
- This ``property`` determines the approach to bundling of short option.
131
+ This ``property`` determines the approach to bundling of short options.
94
132
 
95
- ``click(cmd: Any = True, ctx: Any = True) -> preparse.Click``
96
- """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
133
+ ``click(cmd: object = True, ctx: object = True) -> preparse.Click``
134
+ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
97
135
 
98
136
  This method returns a decorator that infuses the current instance into ``parse_args``.
99
137
 
@@ -116,8 +154,10 @@ This boolean ``property`` determines whether abbreviations of long options are e
116
154
  ``expectsposix: bool``
117
155
  """"""""""""""""""""""
118
156
 
119
- This boolean ``property`` determines whether the order of arguments to conform to the POSIX standard,
120
- i.e. all arguments after the first positional argument also being positonal.
157
+ This boolean ``property`` determines whether the order of arguments conforms to the POSIX standard,
158
+ i.e. all arguments after the first positional argument are also positional.
159
+ If the value passed to the property is ``"infer"``, the value is inferred from
160
+ the ``POSIXLY_CORRECT`` environment variable.
121
161
 
122
162
  ``optdict: preparse.Optdict``
123
163
  """""""""""""""""""""""""""""
@@ -129,8 +169,8 @@ Options not found within the dictionary
129
169
  cause a ``preparse.PreparseInvalidOptionWarning``
130
170
  and are then assumed to have no arguments.
131
171
 
132
- ``parse_args(args: Optional[Iterable] = None) -> list[str]``
133
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
172
+ ``parse_args(args: Optional[Iterable[object]] = None) -> list[str]``
173
+ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
134
174
 
135
175
  This method is at the core of the class.
136
176
  It returns a preparsed list of arguments.
@@ -142,19 +182,21 @@ there will be no changes after the first run.
142
182
  """""""""""""
143
183
 
144
184
  This ``str`` property represents the name of the program.
145
- If the value passed to the property is ``None`` then ``str(sys.argv[0])`` is saved.
185
+ If the value passed to the property is ``None`` then ``str(os.path.basename(sys.argv[0]))`` is saved.
146
186
 
147
187
  ``reconcilesorders: bool``
148
188
  """"""""""""""""""""""""""
149
189
 
150
- This boolean ``property`` determines whether compatibility with both orders,
151
- POSIX and the interleaving of options with positonal arguments, should be enforced.
190
+ This boolean ``property`` determines whether compatibility with both POSIX ordering
191
+ and interleaving options with positional arguments should be enforced.
152
192
 
153
193
  ``reflectClickCommand(cmd: click.Command) -> None``
154
194
  """""""""""""""""""""""""""""""""""""""""""""""""""
155
195
 
156
196
  This method alters the current instance to reflect a ``click.Command`` object.
157
197
  Concretely the ``optdict`` property is changed.
198
+ Only entries in each Click option's ``opts`` are reflected; secondary option names
199
+ are not added.
158
200
 
159
201
  ``reflectClickContext(ctx: click.Context) -> None``
160
202
  """""""""""""""""""""""""""""""""""""""""""""""""""
@@ -170,67 +212,25 @@ This ``property`` determines the approach to the special argument ``'--'``.
170
212
  ``todict() -> dict[str, Any]``
171
213
  """"""""""""""""""""""""""""""
172
214
 
173
- This method a ``dict`` representing the current instance.
215
+ This method returns a ``dict`` representing the current instance.
174
216
 
175
217
  ``warn: Callable[[PreparseWarning], Any]``
176
218
  """"""""""""""""""""""""""""""""""""""""""
177
219
 
178
220
  This property holds a function that is called whenever ``parse_args`` encounters a warning.
179
- The warning is given as the only positional arguments.
221
+ The warning is given as the only positional argument.
180
222
  No keyword arguments are given.
181
223
  Its return value is discarded.
182
224
  Therefore, ``str`` is used to discard the warnings.
183
225
 
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
- ~~~~~~~~~
226
+ ``preparse.enums``
227
+ ~~~~~~~~~~~~~~~~~~
228
228
 
229
229
  These classes are subclasses of ``enum.IntEnum``.
230
230
  Any value different from ``0`` (meaning no) and ``1`` (meaning yes) is interpreted as ``2`` (meaning intermediate).
231
231
 
232
- ``class preparse.Tuning``
233
- ^^^^^^^^^^^^^^^^^^^^^^^^^
232
+ ``class preparse.enums.Tuning.Tuning``
233
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
234
234
 
235
235
  +--------------+-------+-----------------------------------------------------------------------------+
236
236
  | Name | Value | Explanation |
@@ -242,8 +242,8 @@ Any value different from ``0`` (meaning no) and ``1`` (meaning yes) is interpret
242
242
  | ``MAINTAIN`` | ``2`` | The PreParser does not make any unforced changes to the aspect in question. |
243
243
  +--------------+-------+-----------------------------------------------------------------------------+
244
244
 
245
- ``class preparse.Nargs``
246
- ^^^^^^^^^^^^^^^^^^^^^^^^
245
+ ``class preparse.enums.Nargs.Nargs``
246
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
247
247
 
248
248
  +-------------------+-------+----------------------------------------------+
249
249
  | Name | Value | Explanation |
@@ -255,49 +255,63 @@ Any value different from ``0`` (meaning no) and ``1`` (meaning yes) is interpret
255
255
  | OPTIONAL_ARGUMENT | ``2`` | The option may take an argument. |
256
256
  +-------------------+-------+----------------------------------------------+
257
257
 
258
- The Warnings
259
- ~~~~~~~~~~~~
258
+ ``preparse.tests``
259
+ ~~~~~~~~~~~~~~~~~~
260
+
261
+ ``preparse.tests.test() -> unittest.TextTestResult``
262
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
263
+
264
+ This project can be tested through its ``test`` function.
265
+
266
+ .. code-block:: python
267
+
268
+ import preparse.tests
269
+ preparse.tests.test()
270
+
271
+ ``preparse.typing``
272
+ ~~~~~~~~~~~~~~~~~~~
273
+
274
+ ``class preparse.typing.SupportsKeysAndGetitem.SupportsKeysAndGetitem``
275
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
276
+
277
+ This protocol is included in the project for type annotation.
278
+
279
+ ``__getitem__(key: Hashable, /) -> object``
280
+ """""""""""""""""""""""""""""""""""""""""""
281
+
282
+ ``keys() -> tuple[Hashable, ...]``
283
+ """"""""""""""""""""""""""""""""""
284
+
285
+ ``preparse.warnings``
286
+ ~~~~~~~~~~~~~~~~~~~~~
260
287
 
261
288
  These classes are subclasses of ``Warning`` that are specifically designed to communicate issues with parsing.
262
289
 
263
- ``class preparse.PreparseWarning``
264
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
290
+ ``class preparse.warnings.PreparseWarning.PreparseWarning(**kwargs: Any)``
291
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
265
292
 
266
293
  This abstract base ``class`` is the base for all other warning types.
267
294
 
268
- ``class preparse.PreparseAmbiguousOptionWarning(prog: Any, option: Any, possibilities: Any)``
269
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
295
+ ``class preparse.warnings.PreparseAmbiguousOptionWarning.PreparseAmbiguousOptionWarning(*, prog: Any, option: Any, possibilities: Any)``
296
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
270
297
 
271
298
  This ``class`` warns about ambiguous options. This can only happen for long options.
272
299
 
273
- ``class preparse.PreparseInvalidOptionWarning(prog: Any, option: Any, islong: Any)``
274
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
300
+ ``class preparse.warnings.PreparseInvalidOptionWarning.PreparseInvalidOptionWarning(*, prog: object, option: object, islong: object)``
301
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
275
302
 
276
303
  This ``class`` warns about invalid options.
277
304
 
278
- ``class preparse.PreparseRequiredArgumentWarning(prog: Any, option: Any, islong: Any)``
279
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
305
+ ``class preparse.warnings.PreparseRequiredArgumentWarning.PreparseRequiredArgumentWarning(*, prog: object, option: object, islong: object)``
306
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
280
307
 
281
308
  This ``class`` warns about missing required arguments.
282
309
 
283
- ``class preparse.PreparseUnallowedArgumentWarning(prog: Any, option: Any)``
284
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
310
+ ``class preparse.warnings.PreparseUnallowedArgumentWarning.PreparseUnallowedArgumentWarning(*, prog: object, option: object)``
311
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
285
312
 
286
313
  This ``class`` warns about unallowed arguments. This can only happen for long options.
287
314
 
288
- The Tests
289
- ~~~~~~~~~
290
-
291
- ``preparse.tests.test() -> unittest.TextTestResult``
292
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
293
-
294
- This project can be tested through its ``test`` function.
295
-
296
- .. code-block:: python
297
-
298
- import preparse.tests
299
- preparse.tests.test()
300
-
301
315
  License
302
316
  -------
303
317
 
@@ -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.9"
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
+ ]
@@ -32,7 +32,7 @@ class Bundle(Option):
32
32
  self.right = right
33
33
 
34
34
  @classmethod
35
- def _split_allowslong(cls: type, chars: str) -> list[str]:
35
+ def _split_allowslong(cls: type[Self], chars: str) -> list[str]:
36
36
  ans: list[str]
37
37
  x: str
38
38
  ans = list()
@@ -44,7 +44,7 @@ class Bundle(Option):
44
44
  return ans
45
45
 
46
46
  @classmethod
47
- def _split_shortonly(cls: type, chars: str) -> list[str]:
47
+ def _split_shortonly(cls: type[Self], chars: str) -> list[str]:
48
48
  ans: list[str]
49
49
  x: str
50
50
  ans = list()
@@ -60,7 +60,7 @@ class Long(Option):
60
60
  return self._fullkey
61
61
 
62
62
  @fullkey.setter
63
- def fullkey(self: Self, x: Any) -> None:
63
+ def fullkey(self: Self, x: object) -> None:
64
64
  self._fullkey = str(x)
65
65
 
66
66
  @classmethod
@@ -1,4 +1,4 @@
1
- from typing import Any
1
+ from typing import Any, cast
2
2
 
3
3
  from preparse._items.Bundle import Bundle
4
4
  from preparse._items.Item import Item
@@ -154,7 +154,7 @@ def digest_special(
154
154
  items: list[Item],
155
155
  *,
156
156
  special: Tuning,
157
- **kwargs: Any,
157
+ **kwargs: bool,
158
158
  ) -> list[Item]:
159
159
  if special == Tuning.MINIMIZE:
160
160
  return digest_special_min(items, **kwargs)
@@ -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))
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import os
4
4
  import sys
5
- from collections.abc import Callable, Iterable
5
+ from collections.abc import Callable, Hashable, Iterable
6
6
  from typing import Any, Optional, Self, cast
7
7
 
8
8
  import click as cl
@@ -16,6 +16,7 @@ from preparse.core.Click import Click
16
16
  from preparse.core.Optdict import Optdict
17
17
  from preparse.enums.Nargs import Nargs
18
18
  from preparse.enums.Tuning import Tuning
19
+ from preparse.typing.SupportsKeysAndGetitem import SupportsKeysAndGetitem
19
20
  from preparse.warnings.PreparseWarning import PreparseWarning
20
21
 
21
22
  __all__ = ["PreParser"]
@@ -29,17 +30,19 @@ class PreParser(Copyable):
29
30
  def __init__(
30
31
  self: Self,
31
32
  *,
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,
38
- optdict: Any = (),
33
+ allowslong: object = True,
34
+ allowsshort: object = True,
35
+ bundling: int = Tuning.MAINTAIN,
36
+ expandsabbr: object = True,
37
+ expectsabbr: object = True,
38
+ expectsposix: object = False,
39
+ optdict: (
40
+ SupportsKeysAndGetitem | Iterable[tuple[Hashable, object]]
41
+ ) = (),
39
42
  prog: object = None,
40
- reconcilesorders: Any = True,
41
- special: Any = Tuning.MAINTAIN,
42
- warn: Callable = str, # type: ignore[type-arg]
43
+ reconcilesorders: object = True,
44
+ special: int = Tuning.MAINTAIN,
45
+ warn: Callable[[PreparseWarning], Any] = str,
43
46
  ) -> None:
44
47
  self._data: dict[str, Any]
45
48
  self._data = dict()
@@ -64,7 +67,7 @@ class PreParser(Copyable):
64
67
  return cast(bool, self._data["allowslong"])
65
68
 
66
69
  @allowslong.setter
67
- def allowslong(self: Self, value: Any) -> None:
70
+ def allowslong(self: Self, value: object) -> None:
68
71
  self._data["allowslong"] = bool(value)
69
72
 
70
73
  @property
@@ -72,7 +75,7 @@ class PreParser(Copyable):
72
75
  return cast(bool, self._data["allowsshort"])
73
76
 
74
77
  @allowsshort.setter
75
- def allowsshort(self: Self, value: Any) -> None:
78
+ def allowsshort(self: Self, value: object) -> None:
76
79
  self._data["allowsshort"] = bool(value)
77
80
 
78
81
  @property
@@ -85,7 +88,7 @@ class PreParser(Copyable):
85
88
  "This property decides how to approach the bundling of short options."
86
89
  self._data["bundling"] = Tuning(value)
87
90
 
88
- def click(self: Self, cmd: Any = True, ctx: Any = True) -> Click:
91
+ def click(self: Self, cmd: object = True, ctx: object = True) -> Click:
89
92
  "This method returns a decorator that infuses the current instance into parse_args."
90
93
  return Click(parser=self, cmd=cmd, ctx=ctx)
91
94
 
@@ -98,7 +101,7 @@ class PreParser(Copyable):
98
101
  return cast(bool, self._data["expandsabbr"])
99
102
 
100
103
  @expandsabbr.setter
101
- def expandsabbr(self: Self, value: Any, /) -> None:
104
+ def expandsabbr(self: Self, value: object, /) -> None:
102
105
  self._data["expandsabbr"] = bool(value)
103
106
 
104
107
  @property
@@ -106,7 +109,7 @@ class PreParser(Copyable):
106
109
  return cast(bool, self._data["expectsabbr"])
107
110
 
108
111
  @expectsabbr.setter
109
- def expectsabbr(self: Self, value: Any) -> None:
112
+ def expectsabbr(self: Self, value: object) -> None:
110
113
  self._data["expectsabbr"] = bool(value)
111
114
 
112
115
  @property
@@ -114,7 +117,7 @@ class PreParser(Copyable):
114
117
  return cast(bool, self._data["expectsposix"])
115
118
 
116
119
  @expectsposix.setter
117
- def expectsposix(self: Self, value: Any) -> None:
120
+ def expectsposix(self: Self, value: object) -> None:
118
121
  value_: Any
119
122
  if value == "infer":
120
123
  value_ = os.environ.get("POSIXLY_CORRECT")
@@ -162,7 +165,7 @@ class PreParser(Copyable):
162
165
  return cast(bool, self._data["reconcilesorders"])
163
166
 
164
167
  @reconcilesorders.setter
165
- def reconcilesorders(self: Self, value: Any, /) -> None:
168
+ def reconcilesorders(self: Self, value: object, /) -> None:
166
169
  self._data["reconcilesorders"] = bool(value)
167
170
 
168
171
  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, ...]: ...
@@ -14,8 +14,8 @@ class PreparseAmbiguousOptionWarning(PreparseLongonlyWarning):
14
14
  def __post_init__(
15
15
  self: Self,
16
16
  *,
17
- prog: Any,
18
- option: Any,
17
+ prog: object,
18
+ option: object,
19
19
  possibilities: Iterable[object],
20
20
  ) -> None:
21
21
  self.prog = prog
@@ -36,5 +36,5 @@ class PreparseAmbiguousOptionWarning(PreparseLongonlyWarning):
36
36
  return cast(tuple[str, ...], self._data["possibilities"])
37
37
 
38
38
  @possibilities.setter
39
- def possibilities(self: Self, value: Iterable[object]) -> None:
39
+ def possibilities(self: Self, value: Iterable[object], /) -> None:
40
40
  self._data["possibilities"] = tuple(map(str, value))
@@ -12,7 +12,11 @@ class PreparseDualWarning(PreparseWarning):
12
12
 
13
13
  @setdoc.basic
14
14
  def __post_init__(
15
- self: Self, *, prog: Any, option: Any, islong: Any
15
+ self: Self,
16
+ *,
17
+ prog: object,
18
+ option: object,
19
+ islong: object,
16
20
  ) -> None:
17
21
  self.prog = prog
18
22
  self.option = option
@@ -38,5 +42,5 @@ class PreparseDualWarning(PreparseWarning):
38
42
  return cast(bool, self._data["islong"])
39
43
 
40
44
  @islong.setter
41
- def islong(self: Self, value: Any) -> None:
45
+ def islong(self: Self, value: object, /) -> None:
42
46
  self._data["islong"] = bool(value)
@@ -12,7 +12,7 @@ class PreparseUnallowedArgumentWarning(PreparseLongonlyWarning):
12
12
  # option is always full key without value
13
13
 
14
14
  @setdoc.basic
15
- def __post_init__(self: Self, *, prog: Any, option: Any) -> None:
15
+ def __post_init__(self: Self, *, prog: object, option: object) -> None:
16
16
  self.prog = prog
17
17
  self.option = option
18
18
 
@@ -42,7 +42,7 @@ class PreparseWarning(Warning, Copyable):
42
42
  return cast(str, self._data["option"])
43
43
 
44
44
  @option.setter
45
- def option(self: Self, value: object) -> None:
45
+ def option(self: Self, value: object, /) -> None:
46
46
  self._data["option"] = str(value)
47
47
 
48
48
  @property
@@ -50,7 +50,7 @@ class PreparseWarning(Warning, Copyable):
50
50
  return cast(str, self._data["prog"])
51
51
 
52
52
  @prog.setter
53
- def prog(self: Self, value: object) -> None:
53
+ def prog(self: Self, value: object, /) -> None:
54
54
  self._data["prog"] = str(value)
55
55
 
56
56
  def todict(self: Self) -> dict[str, Any]:
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.9
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,8 @@ 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/SupportsKeysAndGetitem.py
46
+ src/preparse/typing/__init__.py
45
47
  src/preparse/warnings/PreparseAmbiguousOptionWarning.py
46
48
  src/preparse/warnings/PreparseDualWarning.py
47
49
  src/preparse/warnings/PreparseInvalidOptionWarning.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes