From afc7442e22e629038b84990200d066058f6be4c6 Mon Sep 17 00:00:00 2001
From: Ran Benita <ran@unusedvar.com>
Date: Sat, 23 Oct 2021 21:40:57 +0300
Subject: [PATCH] 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.
---
 src/_pytest/config/compat.py | 13 +++++++++++--
 src/_pytest/nodes.py         | 22 +++-------------------
 2 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/src/_pytest/config/compat.py b/src/_pytest/config/compat.py
index c93f3738d..731641dde 100644
--- a/src/_pytest/config/compat.py
+++ b/src/_pytest/config/compat.py
@@ -4,8 +4,9 @@ from pathlib import Path
 from typing import Optional
 
 from ..compat import LEGACY_PATH
+from ..compat import legacy_path
 from ..deprecated import HOOK_LEGACY_PATH_ARG
-from _pytest.nodes import _imply_path
+from _pytest.nodes import _check_path
 
 # hookname: (Path, LEGACY_PATH)
 imply_paths_hooks = {
@@ -52,7 +53,15 @@ class PathAwareHookProxy:
                         ),
                         stacklevel=2,
                     )
-                path_value, fspath_value = _imply_path(path_value, fspath_value)
+                if path_value is not None:
+                    if fspath_value is not None:
+                        _check_path(path_value, fspath_value)
+                    else:
+                        fspath_value = legacy_path(path_value)
+                else:
+                    assert fspath_value is not None
+                    path_value = Path(fspath_value)
+
                 kw[path_var] = path_value
                 kw[fspath_var] = fspath_value
                 return hook(**kw)
diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py
index 0a5acbad9..33bf1062b 100644
--- a/src/_pytest/nodes.py
+++ b/src/_pytest/nodes.py
@@ -101,23 +101,7 @@ def _check_path(path: Path, fspath: LEGACY_PATH) -> None:
         )
 
 
-def _imply_path(
-    path: Optional[Path], fspath: Optional[LEGACY_PATH]
-) -> Tuple[Path, LEGACY_PATH]:
-    if path is not None:
-        if fspath is not None:
-            _check_path(path, fspath)
-        else:
-            fspath = legacy_path(path)
-        return path, fspath
-    else:
-        assert fspath is not None
-        return Path(fspath), fspath
-
-
-# Optimization: use _imply_path_only over _imply_path when only need Path.
-# This is to avoid `legacy_path(path)` which is surprisingly heavy.
-def _imply_path_only(path: Optional[Path], fspath: Optional[LEGACY_PATH]) -> Path:
+def _imply_path(path: Optional[Path], fspath: Optional[LEGACY_PATH]) -> Path:
     if path is not None:
         if fspath is not None:
             _check_path(path, fspath)
@@ -212,7 +196,7 @@ class Node(metaclass=NodeMeta):
         #: Filesystem path where this node was collected from (can be None).
         if path is None and fspath is None:
             path = getattr(parent, "path", None)
-        self.path = _imply_path_only(path, fspath=fspath)
+        self.path = _imply_path(path, fspath=fspath)
 
         # The explicit annotation is to avoid publicly exposing NodeKeywords.
         #: Keywords/markers collected from all scopes.
@@ -589,7 +573,7 @@ class FSCollector(Collector):
                 assert path is None
                 path = path_or_parent
 
-        path = _imply_path_only(path, fspath=fspath)
+        path = _imply_path(path, fspath=fspath)
         if name is None:
             name = path.name
             if parent is not None and parent.path != path: