Skip to content

Commit f0d61a6

Browse files
committed
config: drop caching from DropShorterLongHelpFormatter
Unlike what the comment says, it is not called multiple times when `--help` is used (it is not used at all when not).
1 parent 1020d47 commit f0d61a6

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

src/_pytest/config/argparsing.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
409409
410410
- Collapse **long** options that are the same except for extra hyphens.
411411
- Shortcut if there are only two options and one of them is a short one.
412-
- Cache result on the action object as this is called at least 2 times.
413412
"""
414413

415414
def __init__(self, *args: Any, **kwargs: Any) -> None:
@@ -422,13 +421,9 @@ def _format_action_invocation(self, action: argparse.Action) -> str:
422421
orgstr = super()._format_action_invocation(action)
423422
if orgstr and orgstr[0] != "-": # only optional arguments
424423
return orgstr
425-
res: str | None = getattr(action, "_formatted_action_invocation", None)
426-
if res:
427-
return res
428424
options = orgstr.split(", ")
429425
if len(options) == 2 and (len(options[0]) == 2 or len(options[1]) == 2):
430426
# a shortcut for '-h, --help' or '--abc', '-a'
431-
action._formatted_action_invocation = orgstr # type: ignore
432427
return orgstr
433428
return_list = []
434429
short_long: dict[str, str] = {}
@@ -451,9 +446,7 @@ def _format_action_invocation(self, action: argparse.Action) -> str:
451446
return_list.append(option)
452447
if option[2:] == short_long.get(option.replace("-", "")):
453448
return_list.append(option.replace(" ", "=", 1))
454-
formatted_action_invocation = ", ".join(return_list)
455-
action._formatted_action_invocation = formatted_action_invocation # type: ignore
456-
return formatted_action_invocation
449+
return ", ".join(return_list)
457450

458451
def _split_lines(self, text, width):
459452
"""Wrap lines after splitting on original newlines.

0 commit comments

Comments
 (0)