Repository: pytest-dev/pyfakefs (python)

Issue:
FakeOsModule.walk return a (Path, list, list) generator instead of a (str, list, list) when a pathlib object is used as input
**Describe the bug**
method FakeOsModule.walk of <pyfakefs.fake_os.FakeOsModule> is returning a Path object as first element instead of a string as the os.walk method do.

**How To Reproduce**
```python
from pathlib import Path

# Real os part
import os
os_output = list(os.walk(Path(os.getcwd())))  # Deepest element is a tuple of [str, list, list]
# Example ("C:\\", [], [])

# Fake os part
from pyfakefs import fake_filesystem, fake_os
filesystem = fake_filesystem.FakeFilesystem()
os_module = fake_os.FakeOsModule(filesystem)
fs_output = list(os_module.walk(Path(os_module.getcwd())))  # Deepest element is a tuple of [WindowsPath, list, list]
# Example (WindowsPath(C:\), list, list)
fs_output_str = list(os_module.walk(os_module.getcwd()))  # Deepest element is a tuple of [str, list, list] like os.walk
# Example ("C:\\", [], [])

# Warning as walk will return a tuple if there is no subdirectory or a list of tuple otherwise 
assert type(os_output[0][...][0]) is type(fs_output[0])  # Adapt the element to look at the first element of one of the deepest tuples
```

**Your environment**
platform.platform: Windows-10-10.0.22621-SP0
sys.version: Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct  2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)]
pyfakefs: 5.3.1
pytest: 7.4.3


Pull request description:
Fix result of os.walk with a path-like top directory
- used to return a Path object for the top dir instead of a string
- fixes #915

#### Tasks
- [x] Unit tests added that reproduce the issue or prove feature is working
- [x] Fix or feature added
- [x] Entry to release notes added
- [x] Pre-commit CI shows no errors
- [x] Unit tests passing


Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index b9ae289..de4595e 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -45,7 +45,7 @@ repos:
           - flake8-bugbear
         args: ["--extend-ignore=E203", "--max-line-length=88"]
   - repo: https://github.com/pre-commit/mirrors-mypy
-    rev: v1.7.0
+    rev: v1.7.1
     hooks:
       - id: mypy
         exclude: (docs|pyfakefs/tests)
diff --git a/CHANGES.md b/CHANGES.md
index fef1db8..8e0c238 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,6 +7,8 @@ The released versions correspond to PyPI releases.
 * fixed a problem with patching `_io` under Python 3.12 (see [#910](../../issues/910))
 * fixed a problem with accessing the temp path if emulating Linux under Windows
   (see [#912](../../issues/912))
+* fixed result of `os.walk` with a path-like top directory
+  (see [#915](../../issues/915))
 
 ## [Version 5.3.1](https://pypi.python.org/pypi/pyfakefs/5.3.0) (2023-11-15)
 Mostly a bugfix release.
diff --git a/pyfakefs/fake_scandir.py b/pyfakefs/fake_scandir.py
index cfe9f2f..16c7c34 100644
--- a/pyfakefs/fake_scandir.py
+++ b/pyfakefs/fake_scandir.py
@@ -261,7 +261,7 @@ def walk(filesystem, top, topdown=True, onerror=None, followlinks=False):
             if not topdown:
                 yield top_contents
 
-    return do_walk(to_string(top), top_most=True)
+    return do_walk(make_string_path(to_string(top)), top_most=True)
 
 
 class FakeScanDirModule:


Test patch:
diff --git a/pyfakefs/tests/fake_pathlib_test.py b/pyfakefs/tests/fake_pathlib_test.py
index 81ebdfd..15bb7a0 100644
--- a/pyfakefs/tests/fake_pathlib_test.py
+++ b/pyfakefs/tests/fake_pathlib_test.py
@@ -1139,6 +1139,18 @@ class FakePathlibUsageInOsFunctionsTest(RealPathlibTestCase):
         with self.assertRaises(NotImplementedError):
             self.path(path).group()
 
+    def test_walk(self):
+        """Regression test for #915 - walk results shall be strings."""
+        base_dir = self.make_path("foo")
+        base_path = self.path(base_dir)
+        self.create_dir(base_path)
+        self.create_file(base_path / "1.txt")
+        self.create_file(base_path / "bar" / "2.txt")
+        result = list(step for step in self.os.walk(base_path))
+        assert len(result) == 2
+        assert result[0] == (base_dir, ["bar"], ["1.txt"])
+        assert result[1] == (self.os.path.join(base_dir, "bar"), [], ["2.txt"])
+
 
 class RealPathlibUsageInOsFunctionsTest(FakePathlibUsageInOsFunctionsTest):
     def use_real_fs(self):