preparse 2.0.0.dev7__py3-none-any.whl → 2.0.0.dev10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,11 +15,10 @@ __all__ = ["process"]
15
15
  def process(
16
16
  args: Optional[Iterable] = None,
17
17
  *,
18
+ abbr: Optional[Tuning],
18
19
  allowslong: bool,
19
20
  allowsshort: bool,
20
21
  bundling: Tuning,
21
- expandsabbr: bool,
22
- expectsabbr: bool,
23
22
  expectsposix: bool,
24
23
  optdict: dict,
25
24
  prog: str,
@@ -32,10 +31,9 @@ def process(
32
31
  items = pull(args)
33
32
  items = parse(
34
33
  items,
34
+ abbr=abbr,
35
35
  allowslong=allowslong,
36
36
  allowsshort=allowsshort,
37
- expandsabbr=expandsabbr,
38
- expectsabbr=expectsabbr,
39
37
  expectsposix=expectsposix,
40
38
  optdict=optdict,
41
39
  prog=prog,
@@ -18,7 +18,10 @@ PUAW = warnings.PreparseUnallowedArgumentWarning
18
18
  PRAW = warnings.PreparseRequiredArgumentWarning
19
19
 
20
20
 
21
- def parse(args: list[str], **kwargs: Any) -> list[Item]:
21
+ def parse(
22
+ args: list[str],
23
+ **kwargs: Any,
24
+ ) -> list[Item]:
22
25
  return list(parse_generator(args, **kwargs))
23
26
 
24
27
 
@@ -64,10 +67,9 @@ def parse_cause(
64
67
  def parse_generator(
65
68
  items: list[Positional],
66
69
  *,
70
+ abbr: Optional[Tuning],
67
71
  allowslong: bool,
68
72
  allowsshort: bool,
69
- expandsabbr: bool,
70
- expectsabbr: bool,
71
73
  expectsposix: bool,
72
74
  optdict: dict,
73
75
  prog: str,
@@ -103,11 +105,10 @@ def parse_generator(
103
105
  continue
104
106
  last = parse_option(
105
107
  item.value,
108
+ abbr=abbr,
106
109
  allowslong=allowslong,
107
110
  allowsshort=allowsshort,
108
111
  cause=cause,
109
- expandsabbr=expandsabbr,
110
- expectsabbr=expectsabbr,
111
112
  optdict=optdict,
112
113
  )
113
114
  if not last.ishungry():
@@ -138,9 +139,8 @@ def parse_islong(
138
139
  def parse_long(
139
140
  arg: str,
140
141
  *,
142
+ abbr: Optional[Tuning],
141
143
  cause: FunctionType,
142
- expandsabbr: bool,
143
- expectsabbr: bool,
144
144
  optdict: dict,
145
145
  ) -> Long:
146
146
  ans: Long
@@ -153,7 +153,7 @@ def parse_long(
153
153
  ans.abbrlen = len(ans.fullkey)
154
154
  if ans.fullkey in optdict.keys():
155
155
  parts = [ans.fullkey]
156
- elif expectsabbr:
156
+ elif abbr is not None:
157
157
  parts = parse_long_startswith(ans.abbr, keys=optdict.keys())
158
158
  else:
159
159
  parts = list() # can be assumed
@@ -166,7 +166,7 @@ def parse_long(
166
166
  cause(PAOW, option=arg, possibilities=parts)
167
167
  return ans
168
168
  (ans.fullkey,) = parts
169
- if expandsabbr:
169
+ if abbr == Tuning.MINIMIZE:
170
170
  ans.abbrlen = len(ans.fullkey)
171
171
  ans.nargs = optdict[ans.fullkey]
172
172
  if (ans.nargs == Nargs.NO_ARGUMENT) and (ans.right is not None):
@@ -191,18 +191,16 @@ def parse_long_startswith(
191
191
  def parse_option(
192
192
  arg: str,
193
193
  *,
194
+ abbr: Optional[Tuning],
194
195
  cause: FunctionType,
195
- expandsabbr: bool,
196
- expectsabbr: bool,
197
196
  optdict: dict,
198
197
  **kwargs: Any,
199
198
  ) -> Option:
200
199
  if parse_islong(arg, **kwargs):
201
200
  return parse_long(
202
201
  arg,
202
+ abbr=abbr,
203
203
  cause=cause,
204
- expandsabbr=expandsabbr,
205
- expectsabbr=expectsabbr,
206
204
  optdict=optdict,
207
205
  )
208
206
  else:
@@ -23,11 +23,10 @@ __all__ = ["PreParser"]
23
23
 
24
24
  class PreParser(Copyable):
25
25
 
26
+ abbr: Optional[Tuning]
26
27
  allowslong: bool
27
28
  allowsshort: bool
28
29
  bundling: Tuning
29
- expandsabbr: bool
30
- expectsabbr: bool
31
30
  expectsposix: bool
32
31
  optdict: Optdict
33
32
  prog: str
@@ -41,11 +40,10 @@ class PreParser(Copyable):
41
40
  def __init__(
42
41
  self: Self,
43
42
  *,
43
+ abbr: Optional[Tuning] = Tuning.MINIMIZE,
44
44
  allowslong: Any = True,
45
45
  allowsshort: Any = True,
46
46
  bundling: Any = Tuning.MAINTAIN,
47
- expandsabbr: Any = True,
48
- expectsabbr: Any = True,
49
47
  expectsposix: Any = False,
50
48
  optdict: Any = (),
51
49
  prog: Any = None,
@@ -53,11 +51,10 @@ class PreParser(Copyable):
53
51
  special: Any = Tuning.MAINTAIN,
54
52
  warn: Callable = str,
55
53
  ) -> None:
54
+ self.abbr = abbr
56
55
  self.allowslong = allowslong
57
56
  self.allowsshort = allowsshort
58
57
  self.bundling = bundling
59
- self.expandsabbr = expandsabbr
60
- self.expectsabbr = expectsabbr
61
58
  self.expectsposix = expectsposix
62
59
  self.optdict = optdict
63
60
  self.prog = prog
@@ -69,6 +66,11 @@ class PreParser(Copyable):
69
66
  def __repr__(self: Self) -> str:
70
67
  return datarepr(type(self).__name__, **self.todict())
71
68
 
69
+ @dataprop
70
+ def abbr(self: Self, value: Any) -> bool:
71
+ if value is not None:
72
+ return Tuning(value)
73
+
72
74
  @dataprop
73
75
  def allowslong(self: Self, value: Any) -> bool:
74
76
  return bool(value)
@@ -90,14 +92,6 @@ class PreParser(Copyable):
90
92
  def copy(self: Self) -> Self:
91
93
  return type(self)(**self.todict())
92
94
 
93
- @dataprop
94
- def expandsabbr(self: Self, value: Any) -> bool:
95
- return bool(value)
96
-
97
- @dataprop
98
- def expectsabbr(self: Self, value: Any) -> bool:
99
- return bool(value)
100
-
101
95
  @dataprop
102
96
  def expectsposix(self: Self, value: Any) -> bool:
103
97
  if value == "infer":