Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe1b22a

Browse files
committed
ignore errors when trying to fetch sys.stdin.encoding (closes #17863)
1 parent 7d11004 commit fe1b22a

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.3.2?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #17863: In the interactive console, don't loop forever if the encoding
16+
can't be fetched from stdin.
17+
1518
- Issue #17867: Raise an ImportError if __import__ is not found in __builtins__.
1619

1720
- Issue #17857: Prevent build failures with pre-3.5.0 versions of sqlite3,

Python/pythonrun.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,16 +1237,15 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
12371237
_Py_IDENTIFIER(encoding);
12381238

12391239
if (fp == stdin) {
1240-
/* Fetch encoding from sys.stdin */
1240+
/* Fetch encoding from sys.stdin if possible. */
12411241
v = PySys_GetObject("stdin");
1242-
if (v == NULL || v == Py_None)
1243-
return -1;
1244-
oenc = _PyObject_GetAttrId(v, &PyId_encoding);
1245-
if (!oenc)
1246-
return -1;
1247-
enc = _PyUnicode_AsString(oenc);
1248-
if (enc == NULL)
1249-
return -1;
1242+
if (v && v != Py_None) {
1243+
oenc = _PyObject_GetAttrId(v, &PyId_encoding);
1244+
if (oenc)
1245+
enc = _PyUnicode_AsString(oenc);
1246+
if (!enc)
1247+
PyErr_Clear();
1248+
}
12501249
}
12511250
v = PySys_GetObject("ps1");
12521251
if (v != NULL) {

0 commit comments

Comments
 (0)