From b5dc78007406fedf72fffde62ceb5aaf95d3f23a Mon Sep 17 00:00:00 2001 From: Maciej Urbanski Date: Fri, 11 Oct 2024 00:19:40 +0200 Subject: [PATCH] Fix getdefaultlocale deprecation warning on python 3.11+ --- b2/_internal/arg_parser.py | 9 ++++++++- changelog.d/+getdefaultlocale.fixed.md | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelog.d/+getdefaultlocale.fixed.md diff --git a/b2/_internal/arg_parser.py b/b2/_internal/arg_parser.py index ddfe9d3f..7cf60b86 100644 --- a/b2/_internal/arg_parser.py +++ b/b2/_internal/arg_parser.py @@ -20,6 +20,13 @@ from rst2ansi import rst2ansi +try: + getencoding = locale.getencoding +except AttributeError: # Python <=3.10 + + def getencoding(): + return locale.getdefaultlocale()[1] + class B2RawTextHelpFormatter(argparse.RawTextHelpFormatter): """ @@ -142,7 +149,7 @@ def error(self, message): @classmethod def _get_encoding(cls): - _, locale_encoding = locale.getdefaultlocale() + locale_encoding = getencoding() # Check if the stdout is properly set if sys.stdout.encoding is not None: diff --git a/changelog.d/+getdefaultlocale.fixed.md b/changelog.d/+getdefaultlocale.fixed.md new file mode 100644 index 00000000..0708ea24 --- /dev/null +++ b/changelog.d/+getdefaultlocale.fixed.md @@ -0,0 +1 @@ +Fix `getdefaultlocale` deprecation warning on Python 3.11+.