Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Python 3.10/3.8: shutil.rmtree(None, ignore_errors=True) behaves differently between Windows and *nix platforms #94692

Closed
@RamseyK

Description

@RamseyK

Bug report

Expected behavior: Passing None to shutil.rmtree's path argument should not yield an exception when ignore_errors=True.

Behavior on MacOS Python 3.10 (MacPorts) - Correct behavior:

>>> import shutil
>>> shutil.rmtree(None, ignore_errors=True)
>>> shutil.rmtree(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 712, in rmtree
    onerror(os.lstat, path, sys.exc_info())
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 710, in rmtree
    orig_st = os.lstat(path)
TypeError: lstat: path should be string, bytes or os.PathLike, not NoneType

The above occurs on RedHat Linux 8 Python 3.8 and Python 3.10 as well.

Behavior on Windows (Incorrect/differs from MacOS/Linux):

>>> import shutil
>>> shutil.rmtree(None, ignore_errors=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python310\lib\shutil.py", line 733, in rmtree
    onerror(os.lstat, path, sys.exc_info())
  File "C:\Python310\lib\shutil.py", line 577, in rmtree
    orig_st = os.lstat(path)
TypeError: lstat: path should be string, bytes or os.PathLike, not NoneType
>>> shutil.rmtree(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python310\lib\shutil.py", line 733, in rmtree
    onerror(os.lstat, path, sys.exc_info())
  File "C:\Python310\lib\shutil.py", line 577, in rmtree
    orig_st = os.lstat(path)
TypeError: lstat: path should be string, bytes or os.PathLike, not NoneType

Environment

  • CPython Versions Tested: 3.8.x, 3.10.x
  • Operating Systems: Windows 10 21H2, MacOS, RedHat Linux 8 (x86-64)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions