pytest-dev / pyfakefs

Provides a fake file system that mocks the Python file system modules.
https://pytest-pyfakefs.readthedocs.io
Apache License 2.0
651 stars 91 forks source link

pyfakefs filesystem methods always return paths as `str`: #1087

Closed grafix closed 2 weeks ago

grafix commented 2 weeks ago

Describe the bug pyfakefs filesystem methods that return paths always return them as str:

For example, this breaks the dulwich library, which uses bytes paths and expects to receive bytes paths back from filesystem methods:

>>> from pyfakefs.fake_filesystem_unittest import Patcher
>>> import dulwich.porcelain
>>> with Patcher():
...     dulwich.porcelain.clone("https://github.com/pytest-dev/pyfakefs", "pyfakefs")
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/root/dulwich-pyfakefs/venv/lib/python3.11/site-packages/dulwich/porcelain.py", line 584, in clone
    return client.clone(
           ^^^^^^^^^^^^^
  File "/root/dulwich-pyfakefs/venv/lib/python3.11/site-packages/dulwich/client.py", line 874, in clone
    result = self.fetch(
             ^^^^^^^^^^^
  File "/root/dulwich-pyfakefs/venv/lib/python3.11/site-packages/dulwich/client.py", line 987, in fetch
    target.get_graph_walker(),
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/dulwich-pyfakefs/venv/lib/python3.11/site-packages/dulwich/repo.py", line 633, in get_graph_walker
    for sha in self.refs.as_dict(b"refs/heads").values()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/dulwich-pyfakefs/venv/lib/python3.11/site-packages/dulwich/refs.py", line 239, in as_dict
    keys = self.keys(base)
           ^^^^^^^^^^^^^^^
  File "/root/dulwich-pyfakefs/venv/lib/python3.11/site-packages/dulwich/refs.py", line 217, in keys
    return self.subkeys(base)
           ^^^^^^^^^^^^^^^^^^
  File "/root/dulwich-pyfakefs/venv/lib/python3.11/site-packages/dulwich/refs.py", line 633, in subkeys
    dir = dir.strip(b"/")
          ^^^^^^^^^^^^^^^
TypeError: strip arg must be None or str

How To Reproduce

>>> 

**Your environment**

Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.35 Python 3.11.0rc1 (main, Aug 12 2022, 10:02:14) [GCC 11.2.0] pyfakefs 5.8.dev0 pytest 8.3.3

grafix commented 2 weeks ago

Sorry, I accidentally hit the open issue button before I'd finished typing