Repository navigation
Open
Description
Bug report
import os, shutil
from pathlib import Path
Path('readme.txt').touch()
os.rename('readme.txt', 'README.txt')
print(os.listdir())
Path('README.txt').rename('readme.txt')
print(os.listdir())
shutil.move('readme.txt', 'README.txt')
print(os.listdir())
os.replace('README.txt', 'readme.txt')
print(os.listdir())
Path('readme.txt').move('README.txt')
print(os.listdir())2026-11-21T11:23:56.958254000+0100 maurycy@gimel /tmp/p % uv run --python 3.15 python repro.py
['repro.py', 'README.txt']
['repro.py', 'readme.txt']
['repro.py', 'README.txt']
['repro.py', 'readme.txt']
Traceback (most recent call last):
File "/private/tmp/p/repro.py", line 18, in <module>
Path('readme.txt').move('README.txt')
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/Users/maurycy/.local/share/uv/python/cpython-3.15.2-macos-aarch64-none/lib/python3.15/pathlib/__init__.py", line 1382, in move
ensure_different_files(self, target)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/Users/maurycy/.local/share/uv/python/cpython-3.15.2-macos-aarch64-none/lib/python3.15/pathlib/_os.py", line 303, in ensure_different_files
raise err
OSError: [Errno 22] Source and target are the same file: 'readme.txt' -> 'README.txt'
[1] 2026-11-21T11:23:57.245817000+0100 maurycy@gimel /tmp/p % I guess it likely happens on all case-insensitive filesystems.
There's an explicit exception for this in shutil.move():
Lines 944 to 948 in e0d0f2e
| if _samefile(src, dst) and not os.path.islink(src): | |
| # We might be on a case insensitive filesystem, | |
| # perform the rename anyway. | |
| os.rename(src, dst) | |
| return |
I think this is a good first time issue.
I will not immediately be working on this one.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Activity