On 06/16/2017 01:37 PM, Alexandre Brault wrote:
So a <TemporaryDirectory> if used directly, and a <str> if used as a
context manager. I don't have a copy of 3.6 nor the future 3.7 handy,
so maybe it changed there?
The code in master has the context manager return `self.name`. This
behaviour has (based on looking at the 3.2 tag where TemporaryDirectory
was added) always been used.
It is an often overlooked fact that a context manager is free to return anything, not just itself. So
TemporaryDirectory can create the folder, return the name of the folder, and remove the folder on exit. So no need for
the "extract the name from the object" dance. Interestingly enough, that is what the docs say [1].
Pretty cool.
--
~Ethan~
[1] https://docs.python.org/3/library/tempfile.html#tempfile.TemporaryDirectory
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/