20
20
@dataclass
21
21
class DirectiveBoolArgument : # noqa: D101
22
22
value : bool
23
- regex : re .Pattern [str ]
23
+ regex : Callable [[], re .Pattern [str ] ]
24
24
25
25
26
26
if TYPE_CHECKING : # pragma: no cover
@@ -168,8 +168,9 @@ def warn_invalid_directive_arguments(
168
168
directive : Literal ['include' , 'include-markdown' ],
169
169
page_src_path : str | None ,
170
170
docs_dir : str ,
171
- ) -> None :
171
+ ) -> list [ str ] :
172
172
"""Warns about the invalid arguments passed to a directive."""
173
+ used_arguments = []
173
174
valid_args = (
174
175
INCLUDE_DIRECTIVE_ARGS
175
176
if directive == 'include'
@@ -184,6 +185,9 @@ def warn_invalid_directive_arguments(
184
185
f"Invalid argument '{ maybe_arg } ' in"
185
186
f" '{ directive } ' directive at { location } . Ignoring..." ,
186
187
)
188
+ else :
189
+ used_arguments .append (maybe_arg )
190
+ return used_arguments
187
191
188
192
189
193
def parse_filename_argument (
@@ -202,8 +206,10 @@ def parse_filename_argument(
202
206
return filename , raw_filename
203
207
204
208
205
- def parse_string_argument (match : re .Match [str ]) -> str | None :
209
+ def parse_string_argument (match : re .Match [str ] | None ) -> str | None :
206
210
"""Return the string argument matched by ``match``."""
211
+ if match is None :
212
+ return None
207
213
value = match [1 ]
208
214
if value is None :
209
215
value = match [3 ]
@@ -246,6 +252,7 @@ def parse_bool_options(
246
252
option_names : list [str ],
247
253
defaults : DefaultValues ,
248
254
arguments_string : str ,
255
+ used_arguments : list [str ],
249
256
) -> tuple [DirectiveBoolArgumentsDict , list [str ]]:
250
257
"""Parse boolean options from arguments string."""
251
258
invalid_args : list [str ] = []
@@ -254,16 +261,17 @@ def parse_bool_options(
254
261
for option_name in option_names :
255
262
bool_options [option_name ] = DirectiveBoolArgument (
256
263
value = defaults [option_name ], # type: ignore
257
- regex = ARGUMENT_REGEXES [option_name ]() ,
264
+ regex = ARGUMENT_REGEXES [option_name ],
258
265
)
259
266
260
267
for arg_name , arg in bool_options .items ():
261
- bool_arg_match = arg .regex .search (arguments_string )
262
- if bool_arg_match is None :
268
+ if arg_name not in used_arguments :
263
269
continue
270
+ bool_arg_match = arg .regex ().search (arguments_string )
264
271
try :
265
272
bool_options [arg_name ].value = TRUE_FALSE_STR_BOOL [
266
- bool_arg_match [1 ] or TRUE_FALSE_BOOL_STR [arg .value ]
273
+ (bool_arg_match and bool_arg_match [1 ])
274
+ or TRUE_FALSE_BOOL_STR [arg .value ]
267
275
]
268
276
except KeyError :
269
277
invalid_args .append (arg_name )
0 commit comments