Skip to content

shutil.rmtree breaks on recursive calls with PurePath #124

@zolstein

Description

@zolstein

Running 19.3.0 on macOS Mojave 10.14.6

The following script works when run with python3 (3.7.6) but breaks with graalpython with the following error:

import os
import pathlib
import shutil

a = pathlib.PurePath('a')
ab = a / 'b'
os.makedirs(ab)
shutil.rmtree(a)

Error:

Traceback (most recent call last):
  File "/Users/zach/work/pytz/shutil_test.py", line 8, in <module 'shutil_test.py'>
    shutil.rmtree(a)
  File "/Library/Java/JavaVirtualMachines/graalvm-ce-java8-19.3.0/Contents/Home/jre/languages/python/lib-python/3/shutil.py", line 516, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "/Library/Java/JavaVirtualMachines/graalvm-ce-java8-19.3.0/Contents/Home/jre/languages/python/lib-python/3/shutil.py", line 395, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "/Library/Java/JavaVirtualMachines/graalvm-ce-java8-19.3.0/Contents/Home/jre/languages/python/lib-python/3/shutil.py", line 374, in _rmtree_unsafe
    with os.scandir(path) as scandir_it:
TypeError: path should be string, bytes or os.PathLike, not str

This happens only when trying to remove a directory that has another directory inside it; i.e. shutil.rmtree(ab) works fine. It also works when passing in paths as strings.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions