On 19/11/2019 17:12, Brian Skinn wrote:
@jayvdb on GitHub and I are working on a new version of one of my packages,
stdio-mgr (https://github.com/bskinn/stdio-mgr), with a dramatically expanded
API and capabilities.
Context managers feature heavily in the planned design; part of the design plan
is to allow instantiation of a StdioManager object prior to entering a context,
so that the user can tweak settings on the resulting object beforehand:
cm = StdioManager()
cm.setting = True
cm.other_setting = False
with cm:
{do stuff with stdio managed}
If this paradigm holds, we will *specifically* be exploiting the distinction
between __init__ and __enter__.
-42 to abolishing __enter__.
I concur. Logically the problem that people are complaining about is
that we use open() as the context manager rather than a class that
defers the actual file open to __enter__(). That's fixable by writing
your own wrapper class, but having a builtin file context manager that
deferred resource-consuming actions would be a Good Thing™
How about using Paths as file context managers? Just an idle thought.
--
Rhodri James *-* Kynesim Ltd
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/BJYEZRVTFDYAHROFY3ULSPFRXBII7IGH/
Code of Conduct: http://python.org/psf/codeofconduct/