Skip to content

Commit c1ed1e3

Browse files
authored
Use Path objects within copyfile (#12708)
1 parent a4102a7 commit c1ed1e3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sphinx/util/osutil.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import unicodedata
1212
from io import StringIO
1313
from os import path
14+
from pathlib import Path
1415
from typing import TYPE_CHECKING
1516

1617
from sphinx.locale import __
1718

1819
if TYPE_CHECKING:
19-
from pathlib import Path
2020
from types import TracebackType
2121
from typing import Any
2222

@@ -107,12 +107,15 @@ def copyfile(
107107
108108
.. note:: :func:`copyfile` is a no-op if *source* and *dest* are identical.
109109
"""
110-
if not path.exists(source):
111-
msg = f'{os.fsdecode(source)} does not exist'
110+
# coerce to Path objects
111+
source = Path(source)
112+
dest = Path(dest)
113+
if not source.exists():
114+
msg = f'{source} does not exist'
112115
raise FileNotFoundError(msg)
113116

114117
if (
115-
not (dest_exists := path.exists(dest)) or
118+
not (dest_exists := dest.exists()) or
116119
# comparison must be done using shallow=False since
117120
# two different files might have the same size
118121
not filecmp.cmp(source, dest, shallow=False)
@@ -125,7 +128,7 @@ def copyfile(
125128

126129
msg = __('Aborted attempted copy from %s to %s '
127130
'(the destination path has existing data).')
128-
logger.warning(msg, os.fsdecode(source), os.fsdecode(dest),
131+
logger.warning(msg, source, dest,
129132
type='misc', subtype='copy_overwrite')
130133
return
131134

0 commit comments

Comments
 (0)