|
27 | 27 |
|
28 | 28 | from pylint import interfaces
|
29 | 29 | from pylint import utils as pylint_utils
|
30 |
| -from pylint.config.callback_actions import _CallbackAction |
| 30 | +from pylint.config.callback_actions import _CallbackAction, _ExtendAction |
31 | 31 | from pylint.config.deprecation_actions import _NewNamesAction, _OldNamesAction
|
| 32 | +from pylint.constants import PY38_PLUS |
32 | 33 |
|
33 | 34 | if sys.version_info >= (3, 8):
|
34 | 35 | from typing import Literal
|
@@ -294,7 +295,7 @@ def __init__(
|
294 | 295 | self,
|
295 | 296 | *,
|
296 | 297 | flags: List[str],
|
297 |
| - action: Type[argparse._StoreAction], |
| 298 | + action: Type[argparse.Action], |
298 | 299 | default: _ArgumentTypes,
|
299 | 300 | arg_type: str,
|
300 | 301 | choices: Optional[List[str]],
|
@@ -330,6 +331,50 @@ def __init__(
|
330 | 331 | """
|
331 | 332 |
|
332 | 333 |
|
| 334 | +class _ExtendArgument(_DeprecationArgument): |
| 335 | + """Class for extend arguments to be parsed by an argparse.ArgumentsParser. |
| 336 | +
|
| 337 | + This is based on the parameters passed to argparse.ArgumentsParser.add_message. |
| 338 | + See: |
| 339 | + https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument |
| 340 | + """ |
| 341 | + |
| 342 | + def __init__( |
| 343 | + self, |
| 344 | + *, |
| 345 | + flags: List[str], |
| 346 | + action: Literal["extend"], |
| 347 | + default: _ArgumentTypes, |
| 348 | + arg_type: str, |
| 349 | + metavar: str, |
| 350 | + arg_help: str, |
| 351 | + hide_help: bool, |
| 352 | + section: Optional[str], |
| 353 | + choices: Optional[List[str]], |
| 354 | + dest: Optional[str], |
| 355 | + ) -> None: |
| 356 | + # The extend action is included in the stdlib from 3.8+ |
| 357 | + if PY38_PLUS: |
| 358 | + action_class = argparse._ExtendAction # type: ignore[attr-defined] |
| 359 | + else: |
| 360 | + action_class = _ExtendAction |
| 361 | + |
| 362 | + self.dest = dest |
| 363 | + """The destination of the argument.""" |
| 364 | + |
| 365 | + super().__init__( |
| 366 | + flags=flags, |
| 367 | + action=action_class, |
| 368 | + default=default, |
| 369 | + arg_type=arg_type, |
| 370 | + choices=choices, |
| 371 | + arg_help=arg_help, |
| 372 | + metavar=metavar, |
| 373 | + hide_help=hide_help, |
| 374 | + section=section, |
| 375 | + ) |
| 376 | + |
| 377 | + |
333 | 378 | class _StoreOldNamesArgument(_DeprecationArgument):
|
334 | 379 | """Store arguments while also handling old names.
|
335 | 380 |
|
|
0 commit comments