[issue40701] tempfile mixes str and bytes in an inconsistent manner
Eric L.
report at bugs.python.org
Thu May 21 05:36:26 EDT 2020
Eric L. <ewl+python at lavar.de> added the comment:
In the meantime, I noticed the following in addition:
[ericl at tuxedo ~]$ python3.9
Python 3.9.0a6 (default, Apr 28 2020, 00:00:00)
[GCC 10.0.1 20200430 (Red Hat 10.0.1-0.14)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tempfile.tempdir = b'/tmp'
>>> tempfile.gettempdir()
b'/tmp'
>>> tempfile.tempdir = '/tmp'
>>> tempfile.gettempdirb()
b'/tmp'
This actually explicitly hurts the interface description which states that tempfile.gettempdir() returns a string.
"Encouraged" by this discovery, I've tried to write a patch of tempfile.py addressing the issues discovered. It's my first patch ever of Python so bare with me. The default remains string but if someone _explicitly_ sets tempdir to bytes, it'll become bytes. I've tried all the commands listed previously and it all looks consistent to me.
----------
keywords: +patch
Added file: https://bugs.python.org/file49176/tempfile.py.diff
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40701>
_______________________________________
More information about the Python-bugs-list
mailing list