You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ModificationContext specializes the functionality of AbstractContextManager, for context managers designed to change the value of a state or attribute on entry, and revert it on exit. We have noticed that this style is used by many existing and proposed context managers.
The following classes already present in contextlib are to be refactored to inherit from ModificationContext (with no compatibility issues)
contextlib._RedirectStream, parent of redirect_stdout and redirect_stderr
contextlib.chdir
After this addition, the following issues are rebased, so that their additions inherit from ModificationContext:
It's worth noting that adding this weakens the case for adding the additional more specific subclasses in shutil (which in turn weakens the case for moving chdir), since it makes it easier for folks with a use case for that context manager to write it themselves. However, I'll discuss that more on gh-128432
Feature or enhancement
Proposal:
We add an ABC
ModificationContext
tocontextlib
:ModificationContext
specializes the functionality ofAbstractContextManager
, for context managers designed to change the value of a state or attribute on entry, and revert it on exit. We have noticed that this style is used by many existing and proposed context managers.The following classes already present in
contextlib
are to be refactored to inherit fromModificationContext
(with no compatibility issues)contextlib._RedirectStream
, parent ofredirect_stdout
andredirect_stderr
contextlib.chdir
After this addition, the following issues are rebased, so that their additions inherit from
ModificationContext
:shutil.umask
shutil.seteuid
andshutil.setegid
contextlib.chdir
toshutil.chdir
This addition makes those first two PRs trivial, and
contextlib.chdir
is refactored whether it is moved toshutil
or not.Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
Thread started by @ncoghlan
https://discuss.python.org/t/adding-a-contextlib-modificationcontext-base-class/76322/2
The text was updated successfully, but these errors were encountered: