@@ -201,16 +201,30 @@ def _enable_all_extensions(run: Run, value: str | None) -> None:
201
201
202
202
203
203
PREPROCESSABLE_OPTIONS : dict [
204
- str , tuple [bool , Callable [[Run , str | None ], None ]]
204
+ str , tuple [bool , Callable [[Run , str | None ], None ], int ]
205
205
] = { # pylint: disable=consider-using-namedtuple-or-dataclass
206
- "--init-hook" : (True , _init_hook ),
207
- "--rcfile" : (True , _set_rcfile ),
208
- "--output" : (True , _set_output ),
209
- "--load-plugins" : (True , _add_plugins ),
210
- "--verbose" : (False , _set_verbose_mode ),
211
- "-v" : (False , _set_verbose_mode ),
212
- "--enable-all-extensions" : (False , _enable_all_extensions ),
206
+ # pylint: disable=wrong-spelling-in-comment
207
+ # Argparse by default allows abbreviations. It behaves differently
208
+ # if you turn this off, so we also turn it on. We mimick this
209
+ # by allowing some abbreviations or incorrect spelling here.
210
+ # The integer at the end of the tuple indicates how many letters
211
+ # should match, include the '-'. 0 indicates a full match.
212
+ #
213
+ # Clashes with --init-(import)
214
+ "--init-hook" : (True , _init_hook , 8 ),
215
+ # Clashes with --r(ecursive)
216
+ "--rcfile" : (True , _set_rcfile , 4 ),
217
+ # Clashes with --output(-format)
218
+ "--output" : (True , _set_output , 0 ),
219
+ # Clashes with --lo(ng-help)
220
+ "--load-plugins" : (True , _add_plugins , 5 ),
221
+ # Clashes with --v(ariable-rgx)
222
+ "--verbose" : (False , _set_verbose_mode , 4 ),
223
+ "-v" : (False , _set_verbose_mode , 2 ),
224
+ # Clashes with --enable
225
+ "--enable-all-extensions" : (False , _enable_all_extensions , 9 ),
213
226
}
227
+ # pylint: enable=wrong-spelling-in-comment
214
228
215
229
216
230
def _preprocess_options (run : Run , args : Sequence [str ]) -> list [str ]:
@@ -230,12 +244,21 @@ def _preprocess_options(run: Run, args: Sequence[str]) -> list[str]:
230
244
except ValueError :
231
245
option , value = argument , None
232
246
233
- if option not in PREPROCESSABLE_OPTIONS :
247
+ matched_option = None
248
+ for option_name , data in PREPROCESSABLE_OPTIONS .items ():
249
+ to_match = data [2 ]
250
+ if to_match == 0 :
251
+ if option == option_name :
252
+ matched_option = option_name
253
+ elif option .startswith (option_name [:to_match ]):
254
+ matched_option = option_name
255
+
256
+ if matched_option is None :
234
257
processed_args .append (argument )
235
258
i += 1
236
259
continue
237
260
238
- takearg , cb = PREPROCESSABLE_OPTIONS [option ]
261
+ takearg , cb , _ = PREPROCESSABLE_OPTIONS [matched_option ]
239
262
240
263
if takearg and value is None :
241
264
i += 1
0 commit comments