
Safer: A safer file writer for Python - Liriel
https://medium.com/@TomSwirly/%EF%B8%8F-safer-a-safer-file-writer-%EF%B8%8F-5fe267dbe3f5
======
eesmith
Looks like there's no way for me to contact the author without signing up to
some service I don't have, so a few comments here.

line 74: file = str(file)

That looks wrong. If file is a byte string then the result will be
'b"original"'.

The code should probably use os.fspath() on Python 3, which will convert path-
like object to string or byte string path name.

line 75: outs = ('%s.tmp.%d' % (file, i) for i in itertools.count())

A simple replacement with os.fspath() isn't enough, since line 75 also
converts a potential byte-string into a b""-quoted (unicode) string.

I suggest using tempfile.NamedTemporaryFile() instead.

