Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_walk_above_recursion_limit uses absolute limits #116057

Closed
mhsmith opened this issue Feb 28, 2024 · 0 comments · Fixed by #116058
Closed

test_walk_above_recursion_limit uses absolute limits #116057

mhsmith opened this issue Feb 28, 2024 · 0 comments · Fixed by #116058
Labels
type-bug An unexpected behavior, bug, or error

Comments

@mhsmith
Copy link
Member

mhsmith commented Feb 28, 2024

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 exceeded

CPython versions tested on:

CPython main branch

Operating systems tested on:

  • macOS
  • Android

Linked PRs

@mhsmith mhsmith added the type-bug An unexpected behavior, bug, or error label Feb 28, 2024
erlend-aasland pushed a commit that referenced this issue Mar 10, 2024
…ath.walk() (#116058)

Replace test.support.set_recursion_limit with test.support.infinite_recursion.
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
… and Path.walk() (python#116058)

Replace test.support.set_recursion_limit with test.support.infinite_recursion.
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
… and Path.walk() (python#116058)

Replace test.support.set_recursion_limit with test.support.infinite_recursion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant