10
10
import inspect
11
11
import numbers
12
12
import shutil
13
- import textwrap
14
13
from collections import deque
15
14
from typing import Dict , List , Optional , Union
16
15
@@ -95,30 +94,8 @@ def __init__(self, arg_action: argparse.Action) -> None:
95
94
self .max = self .action .nargs
96
95
97
96
98
- class _ArgparseCompletionError (CompletionError ):
99
- """CompletionError specific to argparse-based tab completion"""
100
- pass
101
-
102
-
103
- # noinspection PyProtectedMember
104
- class _ActionCompletionError (_ArgparseCompletionError ):
105
- def __init__ (self , arg_action : argparse .Action , completion_error : CompletionError ) -> None :
106
- """
107
- Adds action-specific information to a CompletionError. These are raised when
108
- non-argparse related errors occur during tab completion.
109
- :param arg_action: action being tab completed
110
- :param completion_error: error that occurred
111
- """
112
- # Indent all lines of completion_error
113
- indented_error = textwrap .indent (str (completion_error ), ' ' )
114
-
115
- error = ("Error tab completing {}:\n "
116
- "{}" .format (argparse ._get_action_name (arg_action ), indented_error ))
117
- super ().__init__ (ansi .style_error (error ))
118
-
119
-
120
97
# noinspection PyProtectedMember
121
- class _UnfinishedFlagError (_ArgparseCompletionError ):
98
+ class _UnfinishedFlagError (CompletionError ):
122
99
def __init__ (self , flag_arg_state : _ArgumentState ) -> None :
123
100
"""
124
101
CompletionError which occurs when the user has not finished the current flag
@@ -128,11 +105,11 @@ def __init__(self, flag_arg_state: _ArgumentState) -> None:
128
105
format (argparse ._get_action_name (flag_arg_state .action ),
129
106
generate_range_error (flag_arg_state .min , flag_arg_state .max ),
130
107
flag_arg_state .count )
131
- super ().__init__ (ansi . style_error ( error ) )
108
+ super ().__init__ (error )
132
109
133
110
134
111
# noinspection PyProtectedMember
135
- class _NoResultsError (_ArgparseCompletionError ):
112
+ class _NoResultsError (CompletionError ):
136
113
def __init__ (self , parser : argparse .ArgumentParser , arg_action : argparse .Action ) -> None :
137
114
"""
138
115
CompletionError which occurs when there are no results. If hinting is allowed, then its message will
@@ -151,7 +128,8 @@ def __init__(self, parser: argparse.ArgumentParser, arg_action: argparse.Action)
151
128
formatter .add_argument (arg_action )
152
129
formatter .end_section ()
153
130
hint_str = formatter .format_help ()
154
- super ().__init__ (hint_str )
131
+ # Set apply_style to False because we don't want hints to look like errors
132
+ super ().__init__ (hint_str , apply_style = False )
155
133
156
134
157
135
# noinspection PyProtectedMember
@@ -253,9 +231,9 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
253
231
if arg_action == completer_action :
254
232
return
255
233
256
- error = ansi . style_error ( " \n Error : argument {}: not allowed with argument {}\n " .
257
- format (argparse ._get_action_name (arg_action ),
258
- argparse ._get_action_name (completer_action )))
234
+ error = ( "Error : argument {}: not allowed with argument {}\n " .
235
+ format (argparse ._get_action_name (arg_action ),
236
+ argparse ._get_action_name (completer_action )))
259
237
raise CompletionError (error )
260
238
261
239
# Mark that this action completed the group
@@ -418,13 +396,8 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
418
396
419
397
# Check if we are completing a flag's argument
420
398
if flag_arg_state is not None :
421
- try :
422
- completion_results = self ._complete_for_arg (flag_arg_state .action , text , line ,
423
- begidx , endidx , consumed_arg_values )
424
- except _ArgparseCompletionError as ex :
425
- raise ex
426
- except CompletionError as ex :
427
- raise _ActionCompletionError (flag_arg_state .action , ex )
399
+ completion_results = self ._complete_for_arg (flag_arg_state .action , text , line ,
400
+ begidx , endidx , consumed_arg_values )
428
401
429
402
# If we have results, then return them
430
403
if completion_results :
@@ -443,13 +416,8 @@ def update_mutex_groups(arg_action: argparse.Action) -> None:
443
416
action = remaining_positionals .popleft ()
444
417
pos_arg_state = _ArgumentState (action )
445
418
446
- try :
447
- completion_results = self ._complete_for_arg (pos_arg_state .action , text , line ,
448
- begidx , endidx , consumed_arg_values )
449
- except _ArgparseCompletionError as ex :
450
- raise ex
451
- except CompletionError as ex :
452
- raise _ActionCompletionError (pos_arg_state .action , ex )
419
+ completion_results = self ._complete_for_arg (pos_arg_state .action , text , line ,
420
+ begidx , endidx , consumed_arg_values )
453
421
454
422
# If we have results, then return them
455
423
if completion_results :
0 commit comments