Skip to content

Commit b7e9612

Browse files
committed
config: make _config_source_hint type safe
Set to `None` instead of using `hasattr`.
1 parent ab2859b commit b7e9612

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/_pytest/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,13 +1306,13 @@ def _unconfigure_python_path(self) -> None:
13061306

13071307
def _validate_args(self, args: list[str], via: str) -> list[str]:
13081308
"""Validate known args."""
1309-
self._parser._config_source_hint = via # type: ignore
1309+
self._parser._config_source_hint = via
13101310
try:
13111311
self._parser.parse_known_and_unknown_args(
13121312
args, namespace=copy.copy(self.option)
13131313
)
13141314
finally:
1315-
del self._parser._config_source_hint # type: ignore
1315+
self._parser._config_source_hint = None
13161316

13171317
return args
13181318

src/_pytest/config/argparsing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(
5454
# Maps alias -> canonical name.
5555
self._ini_aliases: dict[str, str] = {}
5656
self.extra_info: dict[str, Any] = {}
57+
self._config_source_hint: str | None = None
5758

5859
def processoption(self, option: Argument) -> None:
5960
if self._processopt:
@@ -460,7 +461,7 @@ def error(self, message: str) -> NoReturn:
460461
"""Transform argparse error message into UsageError."""
461462
msg = f"{self.prog}: error: {message}"
462463

463-
if hasattr(self._parser, "_config_source_hint"):
464+
if self._parser._config_source_hint is not None:
464465
msg = f"{msg} ({self._parser._config_source_hint})"
465466

466467
raise UsageError(self.format_usage() + msg)

0 commit comments

Comments
 (0)