Skip to content

Commit 7fc91fe

Browse files
committed
config: convert ini type None to string earlier
Do it early so later code doesn't have to deal with `type=None`.
1 parent 68016f0 commit 7fc91fe

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

src/_pytest/config/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,8 +1710,6 @@ def _getini(self, name: str):
17101710
f"Expected a float string for option {name} of type float, but got: {value!r}"
17111711
) from None
17121712
return float(value)
1713-
elif type is None:
1714-
return value
17151713
else:
17161714
return self._getini_unknown_type(name, type, value)
17171715

src/_pytest/config/argparsing.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(
5050
self._groups: list[OptionGroup] = []
5151
self._processopt = processopt
5252
self._usage = usage
53-
self._inidict: dict[str, tuple[str, str | None, Any]] = {}
53+
self._inidict: dict[str, tuple[str, str, Any]] = {}
5454
self._ininames: list[str] = []
5555
# Maps alias -> canonical name.
5656
self._ini_aliases: dict[str, str] = {}
@@ -238,6 +238,8 @@ def addini(
238238
"int",
239239
"float",
240240
)
241+
if type is None:
242+
type = "string"
241243
if default is NOT_SET:
242244
default = get_ini_default_for_type(type)
243245

@@ -255,16 +257,13 @@ def addini(
255257
def get_ini_default_for_type(
256258
type: Literal[
257259
"string", "paths", "pathlist", "args", "linelist", "bool", "int", "float"
258-
]
259-
| None,
260+
],
260261
) -> Any:
261262
"""
262263
Used by addini to get the default value for a given ini-option type, when
263264
default is not supplied.
264265
"""
265-
if type is None:
266-
return ""
267-
elif type in ("paths", "pathlist", "args", "linelist"):
266+
if type in ("paths", "pathlist", "args", "linelist"):
268267
return []
269268
elif type == "bool":
270269
return False

src/_pytest/helpconfig.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ def showhelp(config: Config) -> None:
186186
indent = " " * indent_len
187187
for name in config._parser._ininames:
188188
help, type, _default = config._parser._inidict[name]
189-
if type is None:
190-
type = "string"
191189
if help is None:
192190
raise TypeError(f"help argument cannot be None for {name}")
193191
spec = f"{name} ({type}):"

0 commit comments

Comments
 (0)