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
In contextlib, _RedirectStream (the class behind redirect_stdout and redirect_stderr) returns the current stream target as its context variable, which allows code like this:
This definitely should be documented! Seems like a useful behavior.
Your proposed change looks reasonable. The Optional was a bit surprising to me, but apparently if you do contextlib.redirect_stdout(None) stdout just gets thrown away.
This matches the implementation, even though this behaviour isn't
actually documented yet. https://bugs.python.org/issue41147 aims
to fix the documentation issue though.
Fixespython#4283.
This matches the implementation, even though this behaviour isn't
actually documented yet. https://bugs.python.org/issue41147 aims
to fix the documentation issue though.
Fixes#4283.
In
contextlib
,_RedirectStream
(the class behindredirect_stdout
andredirect_stderr
) returns the current stream target as its context variable, which allows code like this:where you capture the redirected stream without a separate line to declare the variable.
However the typeshed doesn't allow this, because
redirect_stdout
is aContextManager[None]
.I think the fix here would be to have the stub be a
ContextManager[T]
, perhaps like:I'd be happy to put together a PR if we like this approach.
Aside: this behaviour isn't actually included in the docs, though maybe it should be?
The text was updated successfully, but these errors were encountered: