1111import unicodedata
1212from io import StringIO
1313from os import path
14+ from pathlib import Path
1415from typing import TYPE_CHECKING
1516
1617from sphinx .locale import __
1718
1819if 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