Skip to content

Commit afc7442

Browse files
committed
nodes: inline _imply_path
Only one usage left, and we certainly don't expect more! Rename `_imply_path_only` to `_imply_path`, that's a less confusing name now.
1 parent 6be3f31 commit afc7442

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

src/_pytest/config/compat.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from typing import Optional
55

66
from ..compat import LEGACY_PATH
7+
from ..compat import legacy_path
78
from ..deprecated import HOOK_LEGACY_PATH_ARG
8-
from _pytest.nodes import _imply_path
9+
from _pytest.nodes import _check_path
910

1011
# hookname: (Path, LEGACY_PATH)
1112
imply_paths_hooks = {
@@ -52,7 +53,15 @@ def fixed_hook(**kw):
5253
),
5354
stacklevel=2,
5455
)
55-
path_value, fspath_value = _imply_path(path_value, fspath_value)
56+
if path_value is not None:
57+
if fspath_value is not None:
58+
_check_path(path_value, fspath_value)
59+
else:
60+
fspath_value = legacy_path(path_value)
61+
else:
62+
assert fspath_value is not None
63+
path_value = Path(fspath_value)
64+
5665
kw[path_var] = path_value
5766
kw[fspath_var] = fspath_value
5867
return hook(**kw)

src/_pytest/nodes.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,7 @@ def _check_path(path: Path, fspath: LEGACY_PATH) -> None:
101101
)
102102

103103

104-
def _imply_path(
105-
path: Optional[Path], fspath: Optional[LEGACY_PATH]
106-
) -> Tuple[Path, LEGACY_PATH]:
107-
if path is not None:
108-
if fspath is not None:
109-
_check_path(path, fspath)
110-
else:
111-
fspath = legacy_path(path)
112-
return path, fspath
113-
else:
114-
assert fspath is not None
115-
return Path(fspath), fspath
116-
117-
118-
# Optimization: use _imply_path_only over _imply_path when only need Path.
119-
# This is to avoid `legacy_path(path)` which is surprisingly heavy.
120-
def _imply_path_only(path: Optional[Path], fspath: Optional[LEGACY_PATH]) -> Path:
104+
def _imply_path(path: Optional[Path], fspath: Optional[LEGACY_PATH]) -> Path:
121105
if path is not None:
122106
if fspath is not None:
123107
_check_path(path, fspath)
@@ -212,7 +196,7 @@ def __init__(
212196
#: Filesystem path where this node was collected from (can be None).
213197
if path is None and fspath is None:
214198
path = getattr(parent, "path", None)
215-
self.path = _imply_path_only(path, fspath=fspath)
199+
self.path = _imply_path(path, fspath=fspath)
216200

217201
# The explicit annotation is to avoid publicly exposing NodeKeywords.
218202
#: Keywords/markers collected from all scopes.
@@ -589,7 +573,7 @@ def __init__(
589573
assert path is None
590574
path = path_or_parent
591575

592-
path = _imply_path_only(path, fspath=fspath)
576+
path = _imply_path(path, fspath=fspath)
593577
if name is None:
594578
name = path.name
595579
if parent is not None and parent.path != path:

0 commit comments

Comments
 (0)