|  | 
| 41 | 41 | from concurrent.futures.process import ProcessPoolExecutor | 
| 42 | 42 | from dataclasses import dataclass, field | 
| 43 | 43 | from functools import cache, lru_cache, partial, wraps | 
|  | 44 | +from gettext import gettext as _gettext | 
| 44 | 45 | from types import MappingProxyType | 
| 45 | 46 | from typing import (TYPE_CHECKING, Any, Callable, Generic, Literal, NamedTuple, | 
| 46 | 47 |                     Optional, Sequence, Tuple, Type, TypeVar, Union, cast, | 
|  | 
| 70 | 71 | from vllm.logger import enable_trace_function_call, init_logger | 
| 71 | 72 | 
 | 
| 72 | 73 | if TYPE_CHECKING: | 
|  | 74 | +    from argparse import Namespace | 
|  | 75 | + | 
| 73 | 76 |     from vllm.config import ModelConfig, VllmConfig | 
| 74 | 77 | 
 | 
| 75 | 78 | logger = init_logger(__name__) | 
| @@ -1331,24 +1334,35 @@ def __init__(self, *args, **kwargs): | 
| 1331 | 1334 |         if 'formatter_class' not in kwargs: | 
| 1332 | 1335 |             kwargs['formatter_class'] = SortedHelpFormatter | 
| 1333 | 1336 |         super().__init__(*args, **kwargs) | 
|  | 1337 | +        self._deprecated = set() | 
| 1334 | 1338 | 
 | 
| 1335 | 1339 |     def add_argument(self, *args: Any, **kwargs: Any): | 
| 1336 | 1340 |         # add a deprecated=True with optional deprecated_reason to signify | 
| 1337 | 1341 |         # reasons for deprecating this args | 
| 1338 |  | -        if kwargs.pop("deprecated", False): | 
| 1339 |  | -            deprecated_message = kwargs.pop("deprecated_reason", None) | 
| 1340 |  | -            if 'help' in kwargs: | 
| 1341 |  | -                kwargs['help'] = ( | 
| 1342 |  | -                    f"[DEPRECATED]{(' ' + deprecated_message) or ''}.\n{kwargs['help']}"  # noqa: E501 | 
| 1343 |  | -                ) | 
| 1344 |  | -            else: | 
| 1345 |  | -                kwargs['help'] = ( | 
| 1346 |  | -                    f"[DEPRECATED]{(' ' + deprecated_message) or ''}"  # noqa: E501 | 
| 1347 |  | -                ) | 
| 1348 |  | - | 
| 1349 |  | -        super().add_argument(*args, **kwargs) | 
| 1350 |  | - | 
| 1351 |  | -    def parse_args(self, args=None, namespace=None): | 
|  | 1342 | +        if sys.version_info < (3, 13): | 
|  | 1343 | +            deprecated = kwargs.pop('deprecated', False) | 
|  | 1344 | +            action = super().add_argument(*args, **kwargs) | 
|  | 1345 | +            if deprecated and action.dest not in self._deprecated: | 
|  | 1346 | +                self._warning( | 
|  | 1347 | +                    _gettext("argument '%(argument_name)s' is deprecated") % | 
|  | 1348 | +                    {'argument_name': action.dest}) | 
|  | 1349 | +                self._deprecated.add(action.dest) | 
|  | 1350 | + | 
|  | 1351 | +            return action | 
|  | 1352 | + | 
|  | 1353 | +        # python>3.13 | 
|  | 1354 | +        return super().add_argument(*args, **kwargs) | 
|  | 1355 | + | 
|  | 1356 | +    def _warning(self, message: str): | 
|  | 1357 | +        args = {'prog': self.prog, 'message': message} | 
|  | 1358 | +        self._print_message( | 
|  | 1359 | +            _gettext('%(prog)s: warning: %(message)s\n') % args, sys.stderr) | 
|  | 1360 | + | 
|  | 1361 | +    def parse_args(  # type: ignore[override] | 
|  | 1362 | +        self, | 
|  | 1363 | +        args: Sequence[str] | None = None, | 
|  | 1364 | +        namespace: Namespace | None = None, | 
|  | 1365 | +    ): | 
| 1352 | 1366 |         if args is None: | 
| 1353 | 1367 |             args = sys.argv[1:] | 
| 1354 | 1368 | 
 | 
|  | 
0 commit comments