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
subprocess.check_output(['echo', 'test'], text=True, input=None) fails with AttributeError: 'bytes' object has no attribute 'encode' due to the function only checking for universal_newlines but not text:
It seems that allowing input=None to mean "redirect stdin to a pipe and send an empty string there" in subprocess.check_output was an accident(?), and this behavior is inconsistent with subprocess.run and communicate, where input=None has the same effect as not specifying it at all.
The docs for subprocess.check_output say:
The arguments shown above are merely some common ones. The full function signature is largely the same as that of run() - most arguments are passed directly through to that interface. However, explicitly passing input=None to inherit the parent’s standard input file handle is not supported.
They don't make it clear the effect of passing input=None though. I also couldn't find any tests that would check that effect.
Since we can't just forbid input=None for check_output at this point (probably can't even limit that to the case when text is used, since it was added in 3.7), I think that we need to extend the check pointed to by ThiefMaster to cover text, clarify the docs and add a test.
(probably can't even limit that to the case when text is used, since it was added in 3.7)
Well, actually, we can, since we probably don't need to preserve compatibility with the AttributeError currently caused by text=True with input=None. However, it seems to me that treating input=None differently depending on the other arguments would be confusing.