summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 0cd695f36e..b92a8bd9b4 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1255,16 +1255,15 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
_Py_IDENTIFIER(encoding);
if (fp == stdin) {
- /* Fetch encoding from sys.stdin */
+ /* Fetch encoding from sys.stdin if possible. */
v = PySys_GetObject("stdin");
- if (v == NULL || v == Py_None)
- return -1;
- oenc = _PyObject_GetAttrId(v, &PyId_encoding);
- if (!oenc)
- return -1;
- enc = _PyUnicode_AsString(oenc);
- if (enc == NULL)
- return -1;
+ if (v && v != Py_None) {
+ oenc = _PyObject_GetAttrId(v, &PyId_encoding);
+ if (oenc)
+ enc = _PyUnicode_AsString(oenc);
+ if (!enc)
+ PyErr_Clear();
+ }
}
v = PySys_GetObject("ps1");
if (v != NULL) {