On 08/06/17 15:42, Antoine Pietri wrote: > Hello everyone! > > A very common pattern when dealing with temporary files is code like this: > > with tempfile.TemporaryDirectory() as tmpdir: > tmp_path = tmpdir.name > > os.chmod(tmp_path) > os.foobar(tmp_path) > open(tmp_path).read(barquux)
Is it? py> import tempfile py> with tempfile.TemporaryDirectory() as tmpdir: ... print(tmpdir, type(tmpdir)) ... /tmp/tmp2kiqzmi9 <class 'str'> py> > > PEP 519 (https://www.python.org/dev/peps/pep-0519/) introduced the > concept of "path-like objects", objects that define a __fspath__() > method. Most of the standard library has been adapted so that the > functions accept path-like objects. > > My proposal is to define __fspath__() for TemporaryDirectory and > NamedTemporaryFile so that we can pass those directly to the library > functions instead of having to use the .name attribute explicitely. > > Thoughts? :-) > -- Thomas Jollans m ☎ +31 6 42630259 e ✉ t...@tjol.eu _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/