os.walk and Path.walk both have a test verifying that they're not implemented recursively. However, their recursion limits are absolute rather than relative to the current frame. Since the test framework itself already consumes about 30 frames, it only takes a few extra frames to cause a spurious failure. This can easily happen when running the tests within another script, which happens in the Android testbed.
======================================================================
ERROR: test_walk_above_recursion_limit (test.test_pathlib.test_pathlib.PosixPathTest.test_walk_above_recursion_limit)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 241, in __str__
return self._str
^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute '_str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 300, in drive
return self._drv
^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute '_drv'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/msmith/git/python/cpython/Lib/test/test_pathlib/test_pathlib.py", line 1203, in test_walk_above_recursion_limit
list(base.walk())
~~~~^^^^^^^^^^^^^
File "/Users/msmith/git/python/cpython/Lib/pathlib/_abc.py", line 875, in walk
scandir_obj = path._scandir()
~~~~~~~~~~~~~^^
File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 588, in _scandir
return os.scandir(self)
~~~~~~~~~~^^^^^^
File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 177, in __fspath__
return str(self)
~~~^^^^^^
File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 243, in __str__
self._str = self._format_parsed_parts(self.drive, self.root,
^^^^^^^^^^
File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 302, in drive
self._drv, self._root, self._tail_cached = self._parse_path(self._raw_path)
^^^^^^^^^^^^^^
File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 293, in _raw_path
path = self.pathmod.join(*paths)
~~~~~~~~~~~~~~~~~^^^^^^^^
File "<frozen posixpath>", line 77, in join
RecursionError: maximum recursion depth exceeded
Bug report
Bug description:
os.walk and Path.walk both have a test verifying that they're not implemented recursively. However, their recursion limits are absolute rather than relative to the current frame. Since the test framework itself already consumes about 30 frames, it only takes a few extra frames to cause a spurious failure. This can easily happen when running the tests within another script, which happens in the Android testbed.
For example, if the limit in test_pathlib is reduced from 40 to 35:
====================================================================== ERROR: test_walk_above_recursion_limit (test.test_pathlib.test_pathlib.PosixPathTest.test_walk_above_recursion_limit) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 241, in __str__ return self._str ^^^^^^^^^ AttributeError: 'PosixPath' object has no attribute '_str' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 300, in drive return self._drv ^^^^^^^^^ AttributeError: 'PosixPath' object has no attribute '_drv' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/msmith/git/python/cpython/Lib/test/test_pathlib/test_pathlib.py", line 1203, in test_walk_above_recursion_limit list(base.walk()) ~~~~^^^^^^^^^^^^^ File "/Users/msmith/git/python/cpython/Lib/pathlib/_abc.py", line 875, in walk scandir_obj = path._scandir() ~~~~~~~~~~~~~^^ File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 588, in _scandir return os.scandir(self) ~~~~~~~~~~^^^^^^ File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 177, in __fspath__ return str(self) ~~~^^^^^^ File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 243, in __str__ self._str = self._format_parsed_parts(self.drive, self.root, ^^^^^^^^^^ File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 302, in drive self._drv, self._root, self._tail_cached = self._parse_path(self._raw_path) ^^^^^^^^^^^^^^ File "/Users/msmith/git/python/cpython/Lib/pathlib/__init__.py", line 293, in _raw_path path = self.pathmod.join(*paths) ~~~~~~~~~~~~~~~~~^^^^^^^^ File "<frozen posixpath>", line 77, in join RecursionError: maximum recursion depth exceededCPython versions tested on:
CPython main branch
Operating systems tested on:
Linked PRs