Skip to content

Commit 2a91f2e

Browse files
Use fspath to ensure path is str or bytes
1 parent 4705e84 commit 2a91f2e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

atomicwrites/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
except ImportError:
1010
fcntl = None
1111

12+
# `fspath` was added in Python 3.6
13+
try:
14+
from os import fspath
15+
except ImportError:
16+
fspath = None
17+
1218
__version__ = '1.3.0'
1319

1420

@@ -137,6 +143,10 @@ def __init__(self, path, mode=DEFAULT_MODE, overwrite=False,
137143
if 'w' not in mode:
138144
raise ValueError('AtomicWriters can only be written to.')
139145

146+
# Attempt to convert `path` to `str` or `bytes`
147+
if fspath is not None:
148+
path = fspath(path)
149+
140150
self._path = path
141151
self._mode = mode
142152
self._overwrite = overwrite

0 commit comments

Comments
 (0)