Skip to content

Commit d8acf0d

Browse files
authored
bpo-37388: Don't check encoding/errors during finalization (GH-19409)
str.encode() and str.decode() no longer check the encoding and errors in development mode or in debug mode during Python finalization. The codecs machinery can no longer work on very late calls to str.encode() and str.decode(). This change should help to call _PyObject_Dump() to debug during late Python finalization.
1 parent 74e1b6b commit d8acf0d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
str.encode() and str.decode() no longer check the encoding and errors in
2+
development mode or in debug mode during Python finalization. The codecs
3+
machinery can no longer work on very late calls to str.encode() and
4+
str.decode().

Objects/unicodeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,12 @@ unicode_check_encoding_errors(const char *encoding, const char *errors)
451451
return 0;
452452
}
453453

454+
/* Disable checks during Python finalization. For example, it allows to
455+
call _PyObject_Dump() during finalization for debugging purpose. */
456+
if (interp->finalizing) {
457+
return 0;
458+
}
459+
454460
if (encoding != NULL) {
455461
PyObject *handler = _PyCodec_Lookup(encoding);
456462
if (handler == NULL) {

0 commit comments

Comments
 (0)