@@ -1421,8 +1421,9 @@ _set_encodings_path(PyObject *mod) {
14211421 goto exit ;
14221422 }
14231423 const PyConfig * config = _Py_GetConfig ();
1424- /* standard stdlib dir */
14251424 if (config -> stdlib_dir != NULL ) {
1425+ // standard library directory
1426+
14261427 // os.path.join(stdlib_dir, "encodings")
14271428 wchar_t * encodings_dirw = _Py_join_relfile (
14281429 config -> stdlib_dir , L"encodings" );
@@ -1438,9 +1439,8 @@ _set_encodings_path(PyObject *mod) {
14381439 if (PyList_Append (path , encodings_dir ) < 0 ) {
14391440 goto exit ;
14401441 }
1441- }
1442- // Additional search paths, required for embedding
1443- if (config -> module_search_paths_set ) {
1442+ } else if (config -> module_search_paths_set ) {
1443+ // No stdlib_dir, search module_search paths
14441444 for (Py_ssize_t i = 0 ; i < config -> module_search_paths .length ; ++ i ) {
14451445 wchar_t * encodings_dirw = _Py_join_relfile (
14461446 config -> module_search_paths .items [i ], L"encodings" );
@@ -1470,14 +1470,15 @@ _set_encodings_path(PyObject *mod) {
14701470 }
14711471 }
14721472 }
1473- // set and override __path__
1474- if (PyObject_SetAttrString (mod , "__path__" , path ) < 0 ) {
1475- goto exit ;
1473+ if (PyObject_IsTrue (path )) {
1474+ // set and override __path__
1475+ if (PyObject_SetAttrString (mod , "__path__" , path ) < 0 ) {
1476+ goto exit ;
1477+ }
14761478 }
14771479 rc = 0 ;
14781480 exit :
14791481 Py_XDECREF (path );
1480-
14811482 return rc ;
14821483}
14831484
0 commit comments