Skip to content

Commit 38b8d55

Browse files
committed
chore: match upstream 3.13
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
1 parent 861a68e commit 38b8d55

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

vllm/utils.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from concurrent.futures.process import ProcessPoolExecutor
4242
from dataclasses import dataclass, field
4343
from functools import cache, lru_cache, partial, wraps
44+
from gettext import gettext as _gettext
4445
from types import MappingProxyType
4546
from typing import (TYPE_CHECKING, Any, Callable, Generic, Literal, NamedTuple,
4647
Optional, Sequence, Tuple, Type, TypeVar, Union, cast,
@@ -70,6 +71,8 @@
7071
from vllm.logger import enable_trace_function_call, init_logger
7172

7273
if TYPE_CHECKING:
74+
from argparse import Namespace
75+
7376
from vllm.config import ModelConfig, VllmConfig
7477

7578
logger = init_logger(__name__)
@@ -1331,24 +1334,35 @@ def __init__(self, *args, **kwargs):
13311334
if 'formatter_class' not in kwargs:
13321335
kwargs['formatter_class'] = SortedHelpFormatter
13331336
super().__init__(*args, **kwargs)
1337+
self._deprecated = set()
13341338

13351339
def add_argument(self, *args: Any, **kwargs: Any):
13361340
# add a deprecated=True with optional deprecated_reason to signify
13371341
# 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+
):
13521366
if args is None:
13531367
args = sys.argv[1:]
13541368

0 commit comments

Comments
 (0)