11
11
import unicodedata
12
12
from io import StringIO
13
13
from os import path
14
+ from pathlib import Path
14
15
from typing import TYPE_CHECKING
15
16
16
17
from sphinx .locale import __
17
18
18
19
if TYPE_CHECKING :
19
- from pathlib import Path
20
20
from types import TracebackType
21
21
from typing import Any
22
22
@@ -107,12 +107,15 @@ def copyfile(
107
107
108
108
.. note:: :func:`copyfile` is a no-op if *source* and *dest* are identical.
109
109
"""
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'
112
115
raise FileNotFoundError (msg )
113
116
114
117
if (
115
- not (dest_exists := path .exists (dest )) or
118
+ not (dest_exists := dest .exists ()) or
116
119
# comparison must be done using shallow=False since
117
120
# two different files might have the same size
118
121
not filecmp .cmp (source , dest , shallow = False )
@@ -125,7 +128,7 @@ def copyfile(
125
128
126
129
msg = __ ('Aborted attempted copy from %s to %s '
127
130
'(the destination path has existing data).' )
128
- logger .warning (msg , os . fsdecode ( source ), os . fsdecode ( dest ) ,
131
+ logger .warning (msg , source , dest ,
129
132
type = 'misc' , subtype = 'copy_overwrite' )
130
133
return
131
134
0 commit comments