Skip to content

Commit cba7d0c

Browse files
committed
chore: raises OSError if getting locale info failed
1 parent e4983f0 commit cba7d0c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Lib/locale.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,9 @@ def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
557557
1766. code and encoding can be None in case the values cannot
558558
be determined.
559559
560+
Raises OSError on Windows if failed to get locale info (unlikely
561+
to happen on modern Windows).
562+
560563
"""
561564

562565
return _getdefaultlocale(envvars)
@@ -572,12 +575,7 @@ def _getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
572575
else:
573576
# add other platform-specific processing here, if
574577
# necessary...
575-
# for Windows, for any reason if the code was
576-
# not avaliable, fall back to POSIX behaviour
577-
if sys.platform == "win32" and code is None:
578-
pass
579-
else:
580-
return code, encoding
578+
return code, encoding
581579

582580
# fall back on POSIX behaviour
583581
import os

Modules/_localemodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This software comes with no warranty. Use at your own risk.
2929
# define WIN32_LEAN_AND_MEAN
3030
# endif
3131
# include <windows.h>
32+
# include "pyerrors.h" // PyErr_SetFromWindowsErr()
3233
#endif
3334

3435
PyDoc_STRVAR(locale__doc__, "Support for POSIX locales.");
@@ -556,8 +557,8 @@ _locale__getdefaultlocale_impl(PyObject *module)
556557
}
557558

558559
/* cannot determine the language code (very unlikely) */
559-
Py_INCREF(Py_None);
560-
return Py_BuildValue("Os", Py_None, encoding);
560+
/* if any of GetLocaleInfoA above failed */
561+
return PyErr_SetFromWindowsErr(0);
561562
}
562563
#endif
563564

0 commit comments

Comments
 (0)